金額數字轉中文大寫

2021-08-29 13:02:17 字數 1393 閱讀 4806

public class moneyutil ;

/** 整數部分的單位 */

private static final string iunit = ;

/** 小數部分的單位 */

private static final string dunit = ;

/*** 得到大寫金額。

*/public static string tochinese(string str) else if (str.indexof(".") == 0) else

// integerstr去掉首0,不必去掉decimalstr的尾0(超出部分捨去)

if (!integerstr.equals(""))

}// overflow超出處理能力,直接返回

if (integerstr.length() > iunit.length)

int integers = toarray(integerstr);// 整數部分數字

boolean ismust5 = ismust5(integerstr);// 設定萬單位

int decimals = toarray(decimalstr);// 小數部分數字

return getchineseinteger(integers, ismust5) + getchinesedecimal(decimals);

}/**

* 整數部分和小數部分轉換為陣列,從高位至低位

*/private static int toarray(string number)

return array;

}/**

* 得到中文金額的整數部分。

*/private static string getchineseinteger(int integers, boolean ismust5)

: (numbers[integers[i]] + iunit[length - i - 1]));

}return chineseinteger.tostring();

}/**

* 得到中文金額的小數部分。

*/private static string getchinesedecimal(int decimals)

return chinesedecimal.tostring();

}/**

* 判斷第5位數字的單位"萬"是否應加。

*/private static boolean ismust5(string integerstr) else

return integer.parseint(subinteger) > 0;

} else

}public static void main(string args)

}

金額數字轉大寫中文

將數字轉為大寫 public string moneytochinese string lowermoney string strlower null string strupart null string strupper null int itemp 0 保留兩位小數 123.489 123.4...

Util 金額數字轉中文大寫

package com.inforstack.common author cluo 金額數字轉中文大寫 public class moneyutil 整數部分的單位 private static final string iunit 小數部分的單位 private static final stri...

Util 金額數字轉中文大寫

package com.inforstack.common author cluo 金額數字轉中文大寫 public class moneyutil 整數部分的單位 private static final string iunit 小數部分的單位 private static final stri...