Java人民幣金額轉大寫

2021-08-30 02:02:49 字數 1631 閱讀 5460

/*-金額數字轉換為大寫-*/

public class capitalization;

/*漢語中貨幣單位大寫,類似於佔位符*/

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_funll = "零元" + cn_full;

public static string number2cnmontrayunit(double numbermoneypar)

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

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

//得到小數點後兩位值

long scale = number % 100;

int numunit = 0 ;

int numindex = 0;

bollean getzero = false ;

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

if(!(scale > 0))

if((scale > 0 ) && (!(scale % 10 > 0)) )

int zerosize = 0;

while(true)

//每次獲取最後乙個數

numunit = (int) (number % 10);

if(numunit > 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 % 100 > 0) )

getzero = true;

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

number = number / 10;

++numindex;

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

if(signum == -1)

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

if(!(scale > 0 ))

return sb.tostring(); }

}

人民幣數字金額轉大寫金額

public class t if money.substring index,money.length length 3 money money.replaceall d 去除 int length money.length 貨幣大寫形式 string bigletter 貨幣單位 string ...

人民幣小寫金額轉大寫金額

region 人民幣小寫金額轉大寫金額 小寫金額轉大寫金額 接收需要轉換的小寫金額 返回大寫金額 public static string convertmoney this decimal money 生成大寫金額字串 moneystr moneystr dvar unitvar 二次處理大寫金額...

C 人民幣金額轉大寫

using system namespace dotnet.utilities str2 str2.substring 15 j 取出對應位數的str2的值。如 200.55,j為5所以str2 佰拾元角分 迴圈取出每一位需要轉換的值 for i 0 i j i else else else els...