java錢等 數字 大寫數字

2021-08-21 17:27:32 字數 723 閱讀 7066

public string upper(double n) ;//小數部分單位

string num = ;

string unit = , };//單位

string head = n < 0 ? "負" : "";

n = math.abs(n);

string s = "";

for (int i = 0; i < dec.length; i++)

if (s.length() < 1)

int integerpart = (int) math.floor(n);

for (int i = 0; i < unit[0].length && integerpart > 0; i++)

s = p.replaceall("(零.)*零$", "").replaceall("^$", "零") + unit[0][i] + s;

} return head + s.replaceall("(零.)*零元", "元").replacefirst("(零.)+", "").replaceall("(零.)+", "零").replaceall("^整$", "零元整");

}

開收據或者發票時總是需要提供大寫數字,此方法可以 將double型別數字轉換成漢字大寫數字。如果資料庫中的錢數為字串型別則要先轉換成double型別 double n = double.parsedouble(str);

JAVA數字大寫金額轉換

public class moneyutil private static final string iunit private static final string dunit public static string tochinese string str else if str.index...

java 數字金額大寫轉換

數字金額大寫轉換,思想先寫個完整的然後將如零拾替換成零 要用到正規表示式 public static string digituppercase double n string digit string unit string head n 0 負 n math.abs n string s for...

Java數字轉漢字,數字轉大寫

網上找了一圈,都不合我意,自己花點時間寫了一下。數字不好,邏輯差了點,效能應該還可以。如果需要修改為轉財務大寫或轉換為語音檔案的,可以簡單把漢字改乙個就行。執行結果 0 零 1 一 2 二 3 三 4 四 5 五 6 六 7 七 8 八 9 九 10 十 11 十一 20 二十 91 九十一 110...