Java implementation of RMB capitalization conversion method sharing _java

Source: Internet
Author: User

Copy Code code as follows:

/**
* Convert renminbi to Capital
*
* @param value
* @return String
*/
public static String Hangetobig (double value)
{
Char[] Hunit = {' Pick ', ' bai ', ' thousand '}; The position in the paragraph indicates
Char[] Vunit = {' million ', ' billion '}; Paragraph name indicates
char[] digit = {' 0 ', ' one ', ' II ', ' three ', ' Restaurant ', ' Wu ', ' Lu ', ' qi ', ' ba ', ' JIU '}; Digital representation
Long Midval = (long) (value * 100); To be transformed into plastic
String valstr = string.valueof (midval); Into strings
String head = valstr.substring (0, Valstr.length ()-2); Take the whole number of parts
String rail = valstr.substring (Valstr.length ()-2); Take a small number of parts
String prefix = ""; The result of partial transformation of integers
String suffix = ""; The result of the transformation of the decimal part
Handle the number after the decimal point
if (Rail.equals ("00"))
{//If the decimal division is divided into 0
suffix = "whole";
}
Else
{
suffix = Digit[rail.charat (0)-' 0 '] + "angle" + digit[rail.charat (1)-' 0 '] + "min"; Or we'll turn the horn into a dime.
}
Handle the number before the decimal point
char[] Chdig = Head.tochararray (); Converts an integer part into an array of characters
Char zero = ' 0 '; Sign ' 0 ' indicates that there have been 0
byte Zerosernum = 0; The number of consecutive occurrences of 0
for (int i = 0; i < chdig.length; i++)
{//loop process each number
int idx = (chdig.length-i-1)% 4; Take the position within the paragraph
int vidx = (chdig.length-i-1)/4; Take segment position
if (chdig[i] = = ' 0 ')
{//If the current character is 0
zerosernum++; 0 consecutive increments of number
if (zero = ' 0 ')
{//Flag
zero = digit[0];
}
else if (idx = 0 && vidx > 0 && zerosernum < 4)
{
Prefix + = vunit[vidx-1];
Zero = ' 0 ';
}
Continue
}
Zerosernum = 0; 0 consecutive times to clear zero
if (zero!= ' 0 ')
{//If the flag is not 0, add, for example million, billion or something
prefix + = zero;
Zero = ' 0 ';
}
Prefix + + digit[chdig[i]-' 0 ']; Convert the number to represent
if (idx > 0)
Prefix + = hunit[idx-1];
if (idx = = 0 && vidx > 0)
{
Prefix + = vunit[vidx-1]; Paragraph end position should be added to the paragraph name million, billion
}
}
if (prefix.length () > 0)
Prefix + = ' round '; If the integer part exists, then the words with the circle
return prefix + suffix; Returns the correct representation of
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.