/// <summary>
/// 本類實現阿拉伯數字到大寫中文的轉換
/// 該類沒有對非法數字進行判別,請事先自己判斷數字是否合法
/// </summary>
public class ChineseNum
{
//小寫轉大寫
public static string GetChineseNum(string p_num)
{
ChineseNum cn = new ChineseNum();
return cn.NumToChn(p_num);
}
//小寫金額轉大寫金額
public static string GetUpperMoney(double p_Money)
{
ChineseNum cn = new ChineseNum();
return cn.GetMoneyChinese(p_Money);
}
//轉換數字
private char CharToNum(char x)
{
string stringChnNames = "零一二三四五六七八九";
string stringNumNames = "0123456789";
return stringChnNames[stringNumNames.IndexOf(x)];
}
//轉換萬以下整數
private string WanStrToInt(string x)
{
string[] stringArrayLevelNames = new string[4] { "", "十", "百", "千" };
string ret = "";
int i;
for (i = x.Length - 1; i >= 0; i--)
if (x[i] == 0)
{
ret = CharToNum(x[i]) + ret;
}
else
{
ret = CharToNum(x[i]) + stringArrayLevelNames[x.Length - 1 - i] + ret;
}
while ((i = ret.IndexOf("零零")) != -1)
{
ret = ret.Remove(i, 1);
}
if (ret[ret.Length - 1] == 零 && ret.Length > 1)
{
ret = ret.Remove(ret.Length - 1, 1);
}
if (ret.Length >= 2 && ret.Substring(0, 2) == "一十")
{
ret = ret.Remove(0, 1);
}
return ret;
}
//轉換整數
private string StrToInt(string x)
{
int len = x.Length;
string ret, temp;
if (len <= 4)
{
ret = WanStrToInt(x);
}
else if (len <= 8)
{
ret = WanStrToInt(x.Substring(0, len - 4)) + "萬";
temp = WanStrToInt(x.Substring(len - 4, 4));
if (temp.IndexOf("千") == -1 && temp != "")
ret += "零" + temp;
else
ret += temp;
}
else
{
ret = WanStrToInt(x.Substring(0, len - 8)) + "億";
temp = WanStrToInt(x.Substring(len - 8, 4));
if (temp.IndexOf("千") == -1 && temp != "")
{
ret += "零" + temp;
}
else
{
&nbs