当前位置: 编程技术>.net/c#/asp.net
使用C#实现阿拉伯数字到大写中文的转换
来源: 互联网 发布时间:2014-10-13
本文导语: 先记下来,以备后用! /// /// 金额转为大写金额 /// public class MoneyConvertChinese { /// /// 金额转为大写金额 /// /// /// public string MoneyToChinese(string LowerMoney) { string functionReturnValue = null; ...
先记下来,以备后用!
/// /// 金额转为大写金额 /// public class MoneyConvertChinese { /// /// 金额转为大写金额 /// /// /// public string MoneyToChinese(string LowerMoney) { string functionReturnValue = null; bool IsNegative = false; // 是否是负数 if (LowerMoney.Trim().Substring(0, 1) == "-") { // 是负数则先转为正数 LowerMoney = LowerMoney.Trim().Remove(0, 1); IsNegative = true; } string strLower = null; string strUpart = null; string strUpper = null; int iTemp = 0; // 保留两位小数 123.489→123.49 123.4→123.4 LowerMoney = Math.Round(double.Parse(LowerMoney), 2).ToString(); if (LowerMoney.IndexOf(".") > 0) { if (LowerMoney.IndexOf(".") == LowerMoney.Length - 2) { LowerMoney = LowerMoney + "0"; } } else { LowerMoney = LowerMoney + ".00"; } strLower = LowerMoney; iTemp = 1; strUpper = ""; while (iTemp =0;i--) if (x[i] == '0') ret = ToNum(x[i]) + ret; else ret = ToNum(x[i]) + strArrayLevelNames[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 ToInt(string x) { int len = x.Length; string ret,temp; if (len