public static string NumGetStr(string num)
{
try
{
char[] Ls_Shz = new char[] { '零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '扒', '玖' };
string[] Ls_DW_sh = new string[] { "万亿", "拾佰仟", "分角" };
if (string.IsNullOrEmpty(num))
return "";
Regex reg = new Regex(@"/^(([1-9](\d)*)|0)(\.(\d){1,2})?$/g");
string[] strNum = null;
int numLen = 0;
if (num.Contains("."))
{
strNum = num.Split('.');
}
numLen = strNum[0].Length;
string strRtn = string.Empty;
string unit = string.Empty;
for (int a = numLen; a > 0; a--)
{
int intNum_ZS = int.Parse(strNum[0].Substring(numLen - a, 1));
if (a % 4 == 1)
{
unit = (a - 1) / 4 == 0 ? "" : Ls_DW_sh[0].Substring((1 - ((a - 1) / 4) % 2), 1);
if (intNum_ZS != 0)
{
strRtn += Ls_Shz[intNum_ZS] + unit;
}
else if (strRtn != "")
{
if (strRtn.Substring((strRtn.Length - 1),1) == "零")
{
strRtn = strRtn.Substring(0, (strRtn.Length - 1));
strRtn += unit;
}
}
}
else
{
if (intNum_ZS == 0)
{
if (strRtn != "" && strRtn.Substring((strRtn.Length - 1),1) != "零")
strRtn += "零";
}
else if (intNum_ZS == 1 && (a - 2) % 4 == 0)
{
unit = Ls_DW_sh[1].Substring((a - 2) % 4, 1);
strRtn += unit;
}
else
{
unit = Ls_DW_sh[1].Substring((a - 2) % 4, 1);
strRtn += Ls_Shz[intNum_ZS] + unit;
}
}
}
if (strNum.Length == 2)
{
string pointNums = strNum[1].Length < 3 ? strNum[1] : strNum[1].Substring(0, 2);
if (int.Parse(pointNums) == 00)
{
strRtn += strRtn != "" ? "圆整" : "";
}
else
{
if (strRtn != null)
strRtn += "圆";
for (int b = 0; b < pointNums.Length; b++)
{
var d = int.Parse(pointNums.Substring(b, 1));
if (d == 0)
{
if (b == 0 && strRtn != "")
strRtn += "零";
}
else
{
strRtn += Ls_Shz[d] + Ls_DW_sh[2].Substring((1 - b), 1);
}
}
}
if (strRtn == "")
strRtn = "零圆整";
}
else
{
strRtn += strRtn == "" ? "零圆整" : "圆整";
}
return strRtn;
}
catch (Exception ex)
{
throw new Exception("转换为大写金额出错", ex);
}
}
转载于:https://www.cnblogs.com/changweiLi/p/3498020.html