人民币大小写转换
来源:互联网 发布:linux运维之道 编辑:程序博客网 时间:2024/05/16 09:22
- static class Money
- {
- private static string[] NumUpper = { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" };
- private static string[] DanWei = { "1", "10", "100", "1000", "10000", "100000", "1000000", "10000000000" };
- private static string[] DanWeiUpper = { "分", "角", "圆", "拾", "佰", "仟", "萬", "亿" };
- public static string GetMoneyUpper(decimal money)
- {
- money = (long)(Math.Round(money, 2) * 100);
- string result = GetMoneyUpper(money.ToString());
- string lastDanWei = result.Substring(result.Length - 1, 1);
- if (lastDanWei == "圆")
- {
- result += "整";
- }
- else if (lastDanWei != "分" && lastDanWei != "角")
- {
- result += "圆整";
- }
- return result;
- }
- public static string GetMoneyUpper(string money)
- {
- string result = "";
- for (int i = DanWei.Length - 1; i >= 0; i--)
- {
- string _danWei = DanWei[i];
- if (money.Length >= _danWei.Length)
- {
- string moneyTmp = money.Substring(0, money.Length - _danWei.Length + 1);
- if (moneyTmp.Length == 1)
- {
- if (moneyTmp == "0")
- {
- if (DanWeiUpper[i] == "圆")
- result += "圆";
- else
- result += NumUpper[int.Parse(moneyTmp)];
- }
- else
- {
- result += NumUpper[int.Parse(moneyTmp)] + DanWeiUpper[i];
- }
- }
- else
- {
- result += GetMoneyUpper(moneyTmp + "00");
- if (result.Substring(result.Length - 1, 1) == "圆" && DanWeiUpper[i] != "圆")
- result = result.Remove(result.Length - 1);
- result += DanWeiUpper[i];
- }
- money = money.Substring(moneyTmp.Length);
-
- if (string.IsNullOrEmpty(money)) break;
-
- if (int.Parse(money) == 0) break;
-
- int zeroLen = money.Length - int.Parse(money).ToString().Length;
- if (zeroLen > 1)
- {
- if (int.Parse(money) > 9)
- money = "0" + int.Parse(money).ToString();
- else
- money = "00" + int.Parse(money).ToString();
- i = i + zeroLen - 1;
- }
- }
- }
- return result;
- }
- }