/// <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)) + "万";