Transform the digital string of the RMB to uppercase string

xiaoxiao2021-03-06  14

/ *

* Create Date 2005-3-8

*

* Todo To change the template for this generated file, please turn to

* Window - Preferences - Java - Code Style - Code Template

* /

Package com.test;

/ **

* @Author administrator

*

* Todo To change the template for this generated type comment, please turn to

* Window - Preferences - Java - Code Style - Code Template

* /

Public class testRMB {

/ **

* Test NumberConvert method

* @Param args string []

* /

Public static void main (String [] args) {

// This is the largest number that can be converted

String RMB = "90909.99";

System.out.Println (NumberConvert (RMB));

}

/ **

* Translate the character string into Chinese.

* @Param IN number

* @Return Chinese capital

* /

Public Static String NumberConvert (String in) {

StringBuffer out = new stringbuffer ();

String chn [] = {

"Zero", "", "", "", "", "Wu", "Lu", "柒", "捌", "玖"}

String end [] = {

"" "" "," "," 仟 ",}

String mid [] = {

"" "万", "hundred million", "mega",}

Double Ind = double.parsedouble (in);

Long Ind_Left = (long) indifer

Long [] INTE = new long [13]; // Store integer bit

int [] floa = new int [4]; // Store a small number

/ * Put an integer part into intee [] * /

For (int i = 12; I> = 0; I -) {

INTE [I] = (long) (Math.Pow (10, I)));

Ind_Left% = (long) (Math.Pow (10, i));

}

/ * 小 部分 部分 部分 部分 部分入 [] * /

Int index = in.indexof ('.');

IF (INDEX! = -1) {

String str = in.substring (Index 1);

For (int i = 0; i

Floa [I] = integer.parseint (Str.Substring (i, i 1));

}

}

/ ** If the integer bit is not 0, handle an integer example: 111.1234 ** /

IF ((int) ind! = 0) {

INT i = 12;

While (INTE [I] == 0) {file: // Find the first place

I-;

}

/ * Output to OUT * /

For (int J = I / 4; J> = 0; J -) {

IF (j == 3) {// If the number is 13 bits, handle 1 megabo OUT.APpend (INTE [12])]). Append (MID [3]);

J -;

}

For (int K = 3; k> = 0; k -) {

INT NUM = 4 * J K;

IF (INTE [NUM]! = 0) {// No 0 to add 10,000

OUT.APPEND (CHN [NUM])]). Append (end [k]);

}

Else {

IF (k == 0 || K == 0 && k == 1 || K == 0 && k == 1 && k == 2 ||

K == 0 && k == 1 && k == 2 && k == 3) {} // If it is the last few of the trillion, it is not output.

Else {

IF (INTE [NUM - 1] == 0) {} // According to the latter, it is not 0 to determine the addition of 0 examples: 1003

Else {

Out.append (chn [0]);

}

}

}

}

IF (! (INTE [J * 4 0] == 0 && INTE [J * 4 1] == 0 &&

INTE [J * 4 2] == 0 && INTE [J * 4 3] == 0)) {// If there is a full 0 or no output position example: 1000 0000 0003 will not appear one hundred billion Ten only

OUT.APPEND (MID [J]);

}

}

IF (out.charat (0) == 'zero') {// Because the last one does not have the next bit, it is 0 to delete it.

Out.deleteCharat (0);

} // Example 30

}

/ ** If the integer bit is 0, the integer bit is processed, plus 0 examples: 0.1234 ** /

Else {

Out.Append ('zero');

}

/ * Processing the decimal part * /

/ * If there is a small number * /

IF (INDEX! = -1) {

Out.Append ('point'); // Handling a decimal place

For (int m = 0; m <= 3; m ) {

Out.append (chn [floa [m]]);

}

INT ZERO = OUT.LENGTH () - 1;

While (out.charat (zero) == 'zero') {// The last few bits are 0, then delete

Out.deletecharat (zero);

ZERO ---;

}

}

Return out.toString ();

}

}

转载请注明原文地址:https://www.9cbs.com/read-49429.html

New Post(0)