實現阿拉伯數字大寫中文的轉換

2021-06-01 19:48:18 字數 3604 閱讀 6611

///

/// 本類實現阿拉伯數字到大寫中文的轉換

/// 該類沒有對非法數字進行判別,請事先自己判斷數字是否合法

///

public class chinesenum

public static string getuppermoney(double p_money)

//轉換數字

private char chartonum(char x)

//轉換萬以下整數

private string wanstrtoint(string x)

;string ret = "";

int i;

for (i = x.length - 1; i >= 0; i--)

if (x[i] == '0')

else

while ((i = ret.indexof("零零")) != -1)

if (ret[ret.length - 1] == '零' && ret.length > 1)

if (ret.length >= 2 && ret.substring(0, 2) == "一十")

return ret;

}//轉換整數

private string strtoint(string x)

else if (len <= 8)

else

else

ret += "萬";

temp = wanstrtoint(x.substring(len - 4, 4));

if (temp.indexof("千") == -1 && temp != "")

else

}int i;

if ((i = ret.indexof("零萬")) != -1)

while ((i = ret.indexof("零零")) != -1)

if (ret[ret.length - 1] == '零' && ret.length > 1)

return ret;

}//轉換小數

private string strtodouble(string x)

return ret;

}private string numtochn(string x)

string ret = "";

if (x[0] == '-')

if (x[0].tostring() == ".")

if (x[x.length - 1].tostring() == ".")

if (x.indexof(".") > -1)

else

return ret;

}private string getmoneychinese(double money)

mstrsource = money.tostring("#0.00");

i = mstrsource.indexof(".");

if (i > 0)

if (mstrsource.substring(0, 1) == "0")

mstrsource = numstrtochinese(mstrsource);

if (mstrsource.length == 0)

//負if (money < 0)

mstrsource = mstrsource.replace("0", "零");

mstrsource = mstrsource.replace("1", "壹");

mstrsource = mstrsource.replace("2", "貳");

mstrsource = mstrsource.replace("3", "叄");

mstrsource = mstrsource.replace("4", "肆");

mstrsource = mstrsource.replace("5", "伍");

mstrsource = mstrsource.replace("6", "陸");

mstrsource = mstrsource.replace("7", "柒");

mstrsource = mstrsource.replace("8", "捌");

mstrsource = mstrsource.replace("9", "玖");

mstrsource = mstrsource.replace("m", "億");

mstrsource = mstrsource.replace("w", "萬");

mstrsource = mstrsource.replace("s", "仟");

mstrsource = mstrsource.replace("h", "佰");

mstrsource = mstrsource.replace("t", "拾");

mstrsource = mstrsource.replace("y", "圓");

mstrsource = mstrsource.replace("j", "角");

mstrsource = mstrsource.replace("f", "分");

if (mstrsource.substring(mstrsource.length - 1, 1) != "分" || mstrsource.substring(mstrsource.length - 1, 1) != "角")

return mstrsource;

}//金額轉換

private string numstrtochinese(string numstr)

if (mstrchar == "0" && mblnaddzero == false)

if (j == 14)

else

}if (j == 2)

else

//元}

if (j == 6)

else}}

else

else}}

if (j == 10)

else

}if (j == 0 && mstrchar != "0")

if (j == 1 && mstrchar != "0")

if (mstrchar != "0")

}if (mstrreturn.substring(0, 1) == "1" && mstrreturn.substring(1, 1) == mstrflag[1])

if (mstrreturn.substring(mstrreturn.length - 1, 1) == "0")

if (mstrreturn.substring(0, 1) == "0")

if (mstrreturn.substring(mstrreturn.length - 1, 1) == "m" || mstrreturn.substring(mstrreturn.length - 1, 1) == "w" || mstrreturn.substring(mstrreturn.length - 1, 1) == "s" || mstrreturn.substring(mstrreturn.length - 1, 1) == "h" || mstrreturn.substring(mstrreturn.length - 1, 1) == "t")

return mstrreturn;}}

阿拉伯數字大寫轉換

public class genchinese private final static string str shu ji 大數量級 private final static string str shu ji 2 千內數量級 public genchinese param intnumber 需...

阿拉伯數字金額轉換為中文大寫

set ansi nulls on goset quoted identifier on gocreate procedure dbo moneytochinese 阿拉伯數字金額轉換為中文大寫 changemoney money returndaxie varchar 50 output asse...

C 阿拉伯數字轉換為中文大寫

class convertnumber private static string wstr private static string lcstr endregion 轉換方法 輸入引數為阿拉伯數字 返回字串為中文大寫 public static string convertint string ...