Rmb.java
public class Rmb { /** *Basic information and operations of RMB*@author weinee *@version 1.0 */ double number; //Amount of RMB private String[] hanArr = {"zero", "一", "二" , "三", "四", "五", "鲁", "旒", "八", "九" };//Chinese character counting symbols private String[] unitArr = {"", "十", "百", "千"};//Chinese character counting unit private String[] unitArrs = {"万", "Billion", "万", "十大", "万", " "Billion", "Wan", "Yuan"}; //Add units sequentially//private String[] unitsArr = {"Wan", "Billion"}; //The large unit for counting Chinese characters public Rmb(){} /** *Constructor initializes the RMB amount*@param The given initialization RMB number*/ public Rmb(double number){ this.number = number; } /** *Decompose a floating point number into a long part and a decimal part string, The RMB is replaced by an integer. There is an error in the critical value of the floating point number when taking the decimal part*@return Returns the decomposed string array. The first array element is the integer part, and the second is the decimal part string*/ public String [] divideNum(){ double num = Math.round(number*100);//Round number to integer long integerPart = (long)num; //Take the two decimal places into an integer to avoid using subtraction //double decimalsPart = num-integerPart;//The decimal part, an error occurs when critical String decimalsPartStr; long b = integerPart % 10; //The second digit after the decimal point 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}; } /** *Convert a numeric character into Chinese RMB pronunciation*@return Returns the string form of the Chinese RMB pronunciation*/ public String toHanStr(){ String[] results = new String[9]; //Used to temporarily store the numeric string String[] divided into four digits every four digits resultStrs = new String[9];//Used to temporarily store the converted RMB reading after each four-digit segmentation String result = "";//The final conversion result String[] divideStr = divideNum(); //Get the long part and decimal part string that the floating point number is decomposed into. The first array element is the integer part string, and the second is the decimal 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] = "whole"; }else if(results[8].charAt(1) == '0'){ resultStrs[8] = hanArr[results[8].charAt(0) - 48] + "角"; //Change the numbers into Chinese uppercase according to the ASCII code and hanArr array}else{ resultStrs[8] = hanArr[results[8].charAt(0) - 48] + "角" + hanArr[ results[8].charAt(1) - 48] + "point"; } for(int i=0; i<8; i++){ if(results[i] != null){ resultStrs[i] = ""; resultStrs[i] += hanArr[results[i].charAt(0) - 48] + unitArr[results[i].length() - 1]; //Select the number unit based on the ASCII code and array length for (int j=1; j<results[i].length(); j++ ) if(results[i].charAt(j-1) == '0' && results[i].charAt(j) != '0') resultStrs[i] += "zero" + hanArr[results[i ].charAt(j) - 48] + unitArr[results[i].length() - 1 - j]; //Select the number unit based on the ASCII code and array length else if(results[i].charAt(j) != '0' ) resultStrs[i] += hanArr[results[i].charAt(j) - 48] + unitArr[results[i].length() - 1 - j]; } } for (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 amount of RMB to be converted:"); 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 is the entire content of this article. I hope it will be helpful to everyone learning Java.