/// <summary>
/// 将货币数字描述转化成中文描述(整数部分控制在12位,小数部分在2位数)
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static string DoNumberCurrencyToChineseCurrency(string str)
{
if (str.Length < 1)
{
return string.Empty;
}
//去掉描述货币多余的字符[,]
str = str.Replace(",", string.Empty);
str = str.Replace(",", string.Empty);
str = str.Replace("。", ".");
str = str.Replace("-", string.Empty);
str = str.Replace("+", string.Empty);
str = str.Replace("元", string.Empty);
System.Text.RegularExpressions.Regex reg1 = new System.Text.RegularExpressions.Regex(@"^[-]?\d+[.]?\d*$");
if (!reg1.IsMatch(str))
{//参数不是纯数字
return string.Empty;
}
string[] cstr ={ "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" };
string[] wstr ={ "", "", "拾", "佰", "仟", "万", "拾", "佰", "仟", "亿", "拾", "佰", "仟" };
while (str.StartsWith("0"))
{//去掉字符开头的0
str = str.Substring(1, str.Length - 1);
}
string strInt = str;//整数部分字符串
string strDec = string.Empty;//小数部分字符串
string ReturnDec = string.Empty;//返回的小数部分的中文描述
int Index = str.IndexOf(".");//查找是否有小数
if (Index > 0)
{//存在小数
strInt = str.Substring(0, Index);
strDec = str.Substring(Index + 1);
string[] fsstr = new string[] { "角", "分" };
for (int a = 0; a < 2; a++)
{
ReturnDec = ReturnDec + cstr[int.Parse(strDec[a].ToString())] + fsstr[a];
}
}
//计算整数部分
int len = strInt.Length;
int i;
string tmpstr, rstr;
rstr = "";
for (i = 1; i <= len; i++)
{
tmpstr = strInt.Substring(len - i, 1);
rstr = string.Concat(cstr[Int32.Parse(tmpstr)] + wstr[i], rstr);
}
rstr = rstr.Replace("拾零", "拾");
rstr = rstr.Replace("零拾", "零");
rstr = rstr.Replace("零佰", "零");
rstr = rstr.Replace("零仟", "零");
rstr = rstr.Replace("零万", "万");
for (i = 1; i <= 6; i++)
rstr = rstr.Replace("零零", "零");
rstr = rstr.Replace("零万", "零");
rstr = rstr.Replace("零亿", "亿");
rstr = rstr.Replace("零零", "零");
rstr += "元";
if (ReturnDec.Length > 0)
{//存在小数
rstr = rstr + ReturnDec;
}
else
{
rstr += "整";
}
return rstr;
}
/// 将货币数字描述转化成中文描述(整数部分控制在12位,小数部分在2位数)
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static string DoNumberCurrencyToChineseCurrency(string str)
{
if (str.Length < 1)
{
return string.Empty;
}
//去掉描述货币多余的字符[,]
str = str.Replace(",", string.Empty);
str = str.Replace(",", string.Empty);
str = str.Replace("。", ".");
str = str.Replace("-", string.Empty);
str = str.Replace("+", string.Empty);
str = str.Replace("元", string.Empty);
System.Text.RegularExpressions.Regex reg1 = new System.Text.RegularExpressions.Regex(@"^[-]?\d+[.]?\d*$");
if (!reg1.IsMatch(str))
{//参数不是纯数字
return string.Empty;
}
string[] cstr ={ "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" };
string[] wstr ={ "", "", "拾", "佰", "仟", "万", "拾", "佰", "仟", "亿", "拾", "佰", "仟" };
while (str.StartsWith("0"))
{//去掉字符开头的0
str = str.Substring(1, str.Length - 1);
}
string strInt = str;//整数部分字符串
string strDec = string.Empty;//小数部分字符串
string ReturnDec = string.Empty;//返回的小数部分的中文描述
int Index = str.IndexOf(".");//查找是否有小数
if (Index > 0)
{//存在小数
strInt = str.Substring(0, Index);
strDec = str.Substring(Index + 1);
string[] fsstr = new string[] { "角", "分" };
for (int a = 0; a < 2; a++)
{
ReturnDec = ReturnDec + cstr[int.Parse(strDec[a].ToString())] + fsstr[a];
}
}
//计算整数部分
int len = strInt.Length;
int i;
string tmpstr, rstr;
rstr = "";
for (i = 1; i <= len; i++)
{
tmpstr = strInt.Substring(len - i, 1);
rstr = string.Concat(cstr[Int32.Parse(tmpstr)] + wstr[i], rstr);
}
rstr = rstr.Replace("拾零", "拾");
rstr = rstr.Replace("零拾", "零");
rstr = rstr.Replace("零佰", "零");
rstr = rstr.Replace("零仟", "零");
rstr = rstr.Replace("零万", "万");
for (i = 1; i <= 6; i++)
rstr = rstr.Replace("零零", "零");
rstr = rstr.Replace("零万", "零");
rstr = rstr.Replace("零亿", "亿");
rstr = rstr.Replace("零零", "零");
rstr += "元";
if (ReturnDec.Length > 0)
{//存在小数
rstr = rstr + ReturnDec;
}
else
{
rstr += "整";
}
return rstr;
}