C# 金额小写转换为大写

#region 大写转换

public string To_Upper(char NoStr)
{
int No;
int.TryParse(NoStr.ToString(), out No);
if (No > 10 || No < 0) { return ""; } switch (No) { case 0: return "零"; case 1: return "壹"; case 2: return "贰"; case 3: return "叁"; case 4: return "肆"; case 5: return "伍"; case 6: return "陆"; case 7: return "柒"; case 8: return "捌"; case 9: return "玖"; default: return ""; } } public string To_Mon(int a) { if (a > 10)
{
a = a – 8;
return (To_Mon(a));
}
switch (a)
{
case 0: return “分”;
case 1: return “角”;
case 2: return “元”;
case 3: return “拾”;
case 4: return “佰”;
case 5: return “仟”;
case 6: return “万”;
case 7: return “拾”;
case 8: return “佰”;
case 9: return “仟”;
case 10: return “亿”;
default: return “”;
}

}

//直接输入小写金额
public string Get_Upper(string JinE)
{
Decimal JE;
Decimal.TryParse(JinE, out JE);
JE = Math.Round(JE, 2);
JE = JE + 0.0000000001M;
String JEStr = JE.ToString();
string str = JE.ToString().Substring(0, JEStr.IndexOf(“.”) + 3).Replace(“.”, “”).Trim();
char[] c = str.ToCharArray();

int leng = c.Length;
StringBuilder C = new StringBuilder();
for (int i = 0; i < leng; i++) { C .Append(To_Upper(c[i])) .Append(To_Mon(leng - i - 1)) ; } while (true) { var yy = C.Length; C = C.Replace("零分", ""); C = C.Replace("零角", "零"); C = C.Replace("零元", "元"); C = C.Replace("零万", "万"); C = C.Replace("零亿", "亿"); C = C.Replace("零仟", "零"); C = C.Replace("零佰", "零"); C = C.Replace("零零", "零"); C = C.Replace("零拾", "零"); C = C.Replace("亿万", "亿零"); C = C.Replace("万仟", "万零"); C = C.Replace("仟佰", "仟零"); var xx = C.Length; if (yy == xx) { break; } } if (C.ToString().LastIndexOf("零") >= 0)
{
C = C.Replace(“仟佰”, “仟零”).Remove(C.Length – 1, 1);

}

if (C.ToString().LastIndexOf(“元”) == C.Length – 1)
{
C.Append(“整”);
}
return C.ToString();
}

#endregion