數字金額轉成中文大字

2022-02-13 10:56:05 字數 3224 閱讀 7992

///

/// 將金額轉換為漢字

///

public class converter

{public static string convert(double money)

{string strmoney = money.tostring();

string arrarymoney = strmoney.split('.');

//整數部分

stringbuilder builerint = new stringbuilder();

if (arrarymoney != null)

{string moneyint = arrarymoney[0];

int lenofint = moneyint.length;

for (int i = 0; i < lenofint; i++)

{//單位

double unit = double.parse(math.pow(10, lenofint - 1 - i).tostring());

string strunit = integerunittochineseupper(unit);

//數值

string strvalue = numtochineseupper(moneyint[i]);

//小數部份

stringbuilder builerdecimal = new stringbuilder();

if (arrarymoney.length == 2)

{builerint.remove(builerint.length - 1, 1); //移除 "整"

string moneydecimal = arrarymoney[1];

int lenofdecimal = moneydecimal.length;

for (int i = 0; i < lenofdecimal; i++)

{double unit = double.parse(math.pow(10, i).tostring());

string strunit = decimalunittochineseupper(unit);

//數值

string strvalue = numtochineseupper(moneydecimal[i]);

return builerint.tostring() + builerdecimal.tostring();

///

/// 將阿拉伯數字轉換為大寫漢字

///

///

///

private static string numtochineseupper(char charnum)

{string strvalue = string.empty;

switch (charnum)

{case '1': strvalue = "壹"; break;

case '2': strvalue = "貳"; break;

case '3': strvalue = "叄"; break;

case '4': strvalue = "肆"; break;

case '5': strvalue = "伍"; break;

case '6': strvalue = "陸"; break;

case '7': strvalue = "柒"; break;

case '8': strvalue = "捌"; break;

case '9': strvalue = "玖"; break;

case '0': strvalue = "零"; break;

return strvalue;

///

/// 將金額的整數部份轉換為漢字單位

///

///

///

private static string integerunittochineseupper(double unit)

{string strunit = string.empty;

if (unit == 1)

strunit = "元";

else if (unit == 10)

strunit = "拾";

else if (unit == 100)

strunit = "佰";

else if (unit == 1000)

strunit = "仟";

else if (unit == 10000)

strunit = "萬";

else if (unit == 100000)

strunit = "拾";

else if (unit == 1000000)

strunit = "佰";

else if (unit == 10000000)

strunit = "仟";

else if (unit == 100000000)

strunit = "億";

else if (unit == 1000000000)

strunit = "拾";

else if (unit == 10000000000)

strunit = "佰";

else if (unit == 100000000000)

strunit = "仟";

else

strunit = "萬";

return strunit;

///

/// 將金額的小數部份單位轉換為漢字單位

///

///

///

private static string decimalunittochineseupper(double unit)

{string strunit = string.empty;

if (unit == 1)

strunit = "角";

else if (unit == 10)

strunit = "分";

else if (unit == 100)

strunit = "釐";

else if (unit == 1000)

strunit = "毫釐";

else if (unit == 10000)

strunit = "微厘";

else

strunit = "?";

return strunit;

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

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

js數字轉成金額格式

1.方法展示 將數字轉換成金額顯示 function tomoney num 2.方法說明 num num.tofixed 2 將數字轉成帶有2位小數的字串 num parsefloat num 將帶有2位小數的字串轉成帶有小數的數字 num num.tolocalestring 將帶有2位小數的數...

數字金額轉中文大寫金額

用來將數字金額轉化成中文大寫的金額 param value return public static string changetobig double value 段內位置表示 char vunit 段名表示 char digit 數字表示 decimalformat df new decimal...