數字變成大寫金額

2021-08-04 15:54:56 字數 1723 閱讀 3992

/**

* 漢語中數字大寫

*/private static final string cn_upper_number = ;

/*** 漢語中貨幣單位大寫,這樣的設計類似於佔位符

*/private static final string cn_upper_monetray_unit = ;

/*** 特殊字元:整

*/private static final string cn_full = "整";

/*** 特殊字元:負

*/private static final string cn_negative = "負";

/*** 金額的精度,預設值為2

*/private static final int money_precision = 2;

/*** 特殊字元:零元整

*/private static final string cn_zeor_full = "零元" + cn_full;

/*** 把輸入的金額轉換為漢語中人民幣的大寫    

* @param numberofmoney  輸入的金額    

* @return 對應的漢語大寫    

*  */

public static string number2cnmoneyunit(bigdecimal numberofmoney)

//這裡會進行金額的四捨五入

long number = numberofmoney.movepointright(money_precision).setscale(0, 4).abs().longvalue();

// 得到小數點後兩位值

long scale = number % 100;

int numunit = 0;

int numindex = 0;

boolean getzero = false;

// 判斷最後兩位數,一共有四中情況:00 = 0, 01 = 1, 10, 11

if (scale <= 0)

if ((scale > 0) && (scale % 10 <= 0))

int zerosize = 0;

while (number > 0)

if ((numindex == 13) && (zerosize >= 3))

sb.insert(0, cn_upper_monetray_unit[numindex]);

sb.insert(0, cn_upper_number[numunit]);

getzero = false;

zerosize = 0;

} else

if (numindex == 2) else if (((numindex - 2) % 4 == 0) && (number % 1000 > 0))

getzero = true;

}// 讓number每次都去掉最後乙個數

number = number / 10;

++numindex;

}// 如果signum == -1,則說明輸入的數字為負數,就在最前面追加特殊字元:負

if (signum == -1)

// 輸入的數字小數點後兩位為"00"的情況,則要在最後追加特殊字元:整

if (scale <= 0)

return sb.tostring();

}

數字金額轉成大寫中文金額

數字金額轉成大寫中文金額 region 數字金額轉成大寫中文金額 傳入數字字元 如 12121212.232323 public string moneytochinese string strlowermoney switch itemp strupper strupart strupper it...

金額轉成大寫

數字轉換成大寫金額函式 function atoc numbervalue var numbervalue new string math.round numbervalue 100 數字金額 var chinesevalue 轉換後的漢字金額 var string1 零壹貳叄肆伍陸柒捌玖 漢字數字...

數字轉換成大寫金額

數字轉換成大寫金額 using system public class numtocaps 將數定轉換大寫金額格式 引數必須小於萬萬億,且不超過兩位小數多過兩位自動擷取兩位 返回大寫金額 public string getcaps decimal d if d 0 if s.length 0 s.l...