A simple way to translate the digital to Chinese characters

xiaoxiao2021-03-06  42

Package com.abc.ebank.util;

/ ** * @author wangshuangli * * To change this generated comment edit the template variable "typecomment":. * Window> Preferences> Java> Templates * To enable and disable the creation of type comments go to * Window> Preferences> Java> Code generation. * / Public class Digit2chineseNumber {

/ ** * constructor for Digit2ChineseNumber. * / Public Digit2chinesenumber () {super ();} / ** convert the amount lowercase to capital * Method Number2cap. * @Param Amount * @Return String * First turn lowercase digitally converted to uppercase Chinese characters In the middle, do not make other things * then add "10,000" etc; * / public static string number2cap (String amount) {

Amount = Num2chCap (AMOUNT);

INT DECIMAL_ADDRESS; / / Dadix point location If no decimal point value is a value length plus 1; there is a decimal point in the position String S_Decimal = ""; if (Amount.indexof ('.')! = -1) {/ / There is a decimal_address = amount.indexof ('.'); S_decimal = amount.substring (s_decimal.trim (); ife ("zero zero)) {s_decimal =" " Else IF (s_decimal.trim (). Equals ("zero")) {s_decimal = ";} else {s_decimal = decaddunit (s_decimal);}} else {decimal_address = amount.length () 1;} string s_int = Amount.substring (0, decimal_address); s_int = intaddunit; s_int = coordinate_string (s_int); // String string remove some excess things to RETURN S_INT S_DECIMAL "整";

/ ** String string to remove some excess things like zero elevation * Method coordinate_string. * @Param s_int * @Return String * / private static string coordinate_string (string s_int) {int address; // for loop removal zero FOR (; true;) {address = s_int.indexof ("万"); if (address == -1) {address = s_int.indexof ("zero");} if (address == -1) { Address = S_INT.INDEXOF ("Zero");} if (address == -1) {address = s_int.indexof ("zero pick");} if (address == -1) {address = s_int.indexof "零");} if (address == -1) {address = s_int.indexof ("zero element");} if (address == -1) Break; system.err.println (s_int.substring (0 , ADDRESS); System.err.Println (s_int.substring (address 2)); s_int = s_int.substring (0, address) s_int.substring (address 1);} String TMP = "@ 亿 @ 万 万 @ 万 万@ 千 @ @ 万 佰 万 万 万 万 万 佰 佰;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;) {String tmp1 = tmp.substring (i, i 2); address = 0; for (; true;) {address = s_int.indexof (TMP1); if (address == -1) Break; System.err .P RINTLN (s_int.substring (0, address 1)); system.rr.println (s_int.substring (address 2)); s_int = s_int.substring (0, address 1) s_int.substring (Address 2 } I = 2;} return s_int.substring (1);} / ** Add 10,000 佰 万 万 佰 佰 元 元 到 字 位置 位置 位置 位置 位置 位置 位置 位置 位置 位置 元 元 元 元 位置 元 元 位置 位置 位置 位置 位置 位置Return string * / private static string intaddunit (string s_int) {string units = "Yuan Qiu 10,000 yuan to pick up 100 million";

S_INT = StringOverturn (S_INT); INT S_INT_LENGTH = S_INT.LENGTH (); String TMP = ""; for (INT I = 0; I - 1; I - {TMP = TMP OVERTMP [I];} Return TMP;

/ ** Add angle to the string. * @Param s_decimal * @return string * / private static string decaddunit (String Returnstring) {

Switch (Returnstring.Length ()) {// Decimal length is 1 indicating only angleless Case 1: returnstring = returbtring.substring (0, 1) "angle" returbustring.substring (2);

Break; // Decimal length 2 indicates a horned angle. Case 2: returnstring = returbustring.substring (0, 1) "angle" returbtring.substring (1, 2) "points";

Break;} // end of swtich return returbtring;

/ ** Convert the digital to Chinese capital * return format is zib. 贰 * method Num2chcap. * @Param Amount * @return string * / private static string Num2chCap (string amount) {Int length = Amount.length (); CHAR CAPNUMBER; STRING RETURnstring = ""; for (int i = 0; i

// public static void main (string [] args) {//}}

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

New Post(0)