Java to achieve RMB case conversion method sharing
- 2020-04-01 02:46:31
- OfStack
public static String hangeToBig(double value)
{
char[] hunit = { ' Pick up ', ' hk ', ' micky ' }; //In-segment position representation
char[] vunit = { ' wan ', ' Hundred million ' }; //Section name said
char[] digit = { ' zero ', ' one ', ' Ii. ', ' 3 ', ' boss ', ' wu ', ' lu ', ' Retailer, ', ' ', ' nine ' }; //The figures show that the
long midVal = (long) (value * 100); //Convert to shaping
String valStr = String.valueOf(midVal); //Convert to a string
String head = valStr.substring(0, valStr.length() - 2); //Integer part
String rail = valStr.substring(valStr.length() - 2); //Take the fractional part
String prefix = ""; //The result of integer partial transformation
String suffix = ""; //The result of decimal transformation
//We're dealing with Numbers behind the decimal point
if (rail.equals("00"))
{ //If the decimal part is 0
suffix = " The whole ";
}
else
{
suffix = digit[rail.charAt(0) - '0'] + " Angle " + digit[rail.charAt(1) - '0'] + " points "; //Otherwise, convert the Angle out
}
//We're dealing with the number in front of the decimal point
char[] chDig = head.toCharArray(); //Converts the integer part into an array of characters
char zero = '0'; //The flag '0' indicates that a 0 was present
byte zeroSerNum = 0; //The number of consecutive zeros
for (int i = 0; i < chDig.length; i++)
{ //Loop through each number
int idx = (chDig.length - i - 1) % 4; //Take the inside position
int vidx = (chDig.length - i - 1) / 4; //Take long position
if (chDig[i] == '0')
{ //If the current character is 0
zeroSerNum++; //It increases 0 times in a row
if (zero == '0')
{ //mark
zero = digit[0];
}
else if (idx == 0 && vidx > 0 && zeroSerNum < 4)
{
prefix += vunit[vidx - 1];
zero = '0';
}
continue;
}
zeroSerNum = 0; //Zero zeros in a row
if (zero != '0')
{ //If the sign is not zero, then plus, like million, billion or something
prefix += zero;
zero = '0';
}
prefix += digit[chDig[i] - '0']; //Convert the numerical representation
if (idx > 0)
prefix += hunit[idx - 1];
if (idx == 0 && vidx > 0)
{
prefix += vunit[vidx - 1]; //The end of the segment should have the segment name like million, billion
}
}
if (prefix.length() > 0)
prefix += ' round '; //If the integer part exists, there is the word circle
return prefix + suffix; //Return the correct representation
}