Rmb.java
public class RMB {/** * basic information and operations for RMB * @author Weinee * @version/double number; The number of RMB private string[] Hanarr = {"0", "one", "II", "three", "Restaurant", "WU", "Lu", "Qi", "ba", "Nine"};//Chinese character count symbol private string[] UnitA rr = {"", "Pick Up", "Bai", "thousand"};//Chinese character count unit private string[] Unitarrs = {"Million", "billion", "million", "trillion", "million", "billion", "million", "Round"}; Order add unit//private string[] Unitsarr = {"Million", "billion"}; Chinese character count large unit public RMB () {}/** * constructor initializes number of RMB * @param given the initial number of RMB/public RMB (double number) {This.number =
Number
/** * A floating-point number is decomposed into a long and fractional string, the people's currency into an integer, floating point number in the fractional part of the critical value of the error * @return returns the decomposed string array, the first array element is an integer part, and the second is a fractional part string * * Public string[] Dividenum () {Double num = Math.Round (number*100);//number is rounded up to the whole long Integerpart = (long) num;
/with two digits after the decimal point to the integer, to avoid the use of subtraction//double Decimalspart = num-integerpart;//Fractional part, the critical error generated by the String decimalspartstr; Long B = Integerpart% 10;
After the decimal point, the second long a = (INTEGERPART/10)% 10;//The first digit after the decimal point integerpart/= 100; if (A==0 && b==0) {decimalspartstr = null;
}else{decimalspartstr = "" + A + B;
return new string[] {string.valueof (Integerpart), decimalspartstr}; /** * Converts a numeric character into Chinese yuan reading method * @return Returns the string form of the Chinese Yuan Reading method/public string Tohanstr () {string[] results = new S TRING[9];
Used to temporarily store the numeric string after each four-bit fragment string[] Resultstrs = new string[9];//is used to temporarily store the renminbi read after each four-bit fragment = "";//Final conversion results string[] Dividestr = Dividenum ();
Gets the long and fractional string that the floating-point number is decomposed into, the first array element is the integer part string, the second is the fractional part string results[8] = dividestr[1]; for (int i=dividestr[0].length (), j=8 i>0&&j>0; i-=4,j--) {try{results[j-1] = dividestr[0].
SUBSTRING (i-4, i);
}catch (Exception e) {results[j-1] = dividestr[0].substring (0, I);
Break
} if (results[8] = = null) {resultstrs[8] = "integer"; }else if (Results[8].charat (1) = = ' 0 ') {resultstrs[8] = Hanarr[results[8].charat (0)-48] + "Corner";//Based on ASCII and Hanarr array bar Convert number to Chinese capital}else{
RESULTSTRS[8] = Hanarr[results[8].charat (0)-48] + "angle" + hanarr[results[8].charat (1)-48] + "min";
for (int i=0; i<8; i++) {if (results[i)!= null) {Resultstrs[i] = ""; Resultstrs[i] + + hanarr[results[i].charat (0)-1] A unit for (int j=1; j<results[i].length (); j + +) if (Results[i].charat (j-1) = = ' 0 ' &am based on the number of ASCII and array length selections p;& Results[i].charat (j)!= ' 0 ') resultstrs[i] + = "0" + Hanarr[results[i].charat (j)-K] + Unitarr[result S[i].length ()-1-j]; Unit else if (Results[i].charat (j)!= ' 0 ') resultstrs[i] = = Hanarr[results[i].chara based on the number of ASCII code and array length selection
T (j)-K] + unitarr[results[i].length ()-1-j];
(int i=0; i<8; i++) {if (resultstrs[i)!= null) {result = Resultstrs[i] + unitarrs[i];
} result + = Resultstrs[8];
return result; }
}
Rmbtest.java
public class Rmbtest
{public
static void Main (string[] args)
{
double L;
byte[] bye = new BYTE[50];
System.out.println ("Please enter the number of RMB to convert:");
try{
System.in.read (bye);
} catch (Exception e) {}
string s = new string (bye);
L = double.parsedouble (s);
RMB r = new RMB (l);
s = r.tohanstr ();
System.out.println (s);
}
The above mentioned is the entire content of this article, I hope to learn Java can help.