首页 > 代码库 > C# 数字转换成大写
C# 数字转换成大写
1 /// <summary> 2 /// 数字转大写 3 /// </summary> 4 /// <param name="type">单价/数量</param> 5 /// <param name="Num">数字</param> 6 /// <returns></returns> 7 public static string GetChineseNum(string type,string Num) 8 { 9 #region10 try11 {12 string m_1, m_2, m_3, m_4, m_5, m_6, m_7, m_8, m_9;13 m_1 = Num;14 string numNum = "0123456789.";15 string numChina = "零壹贰叁肆伍陆柒捌玖点";16 string numChinaWeigh = "个拾佰仟万拾佰仟亿拾佰仟万";17 if (Num.Substring(0, 1) == "0")//0123-->12318 Num = Num.Substring(1, Num.Length-1);19 if (!Num.Contains(‘.‘))20 Num += ".00";21 else//123.234 123.23 123.222 Num = Num.Substring(0, Num.IndexOf(‘.‘) + 1 + (Num.Split(‘.‘)[1].Length > 2 ? 3 : Num.Split(‘.‘)[1].Length));23 m_1 = Num;24 m_2 = m_1;25 m_3 = m_4 = "";26 //m_2:1234-> 壹贰叁肆27 for (int i = 0; i < 11; i++)28 {29 m_2 = m_2.Replace(numNum.Substring(i, 1), numChina.Substring(i, 1));30 }31 //m_3:佰拾万仟佰拾个32 int iLen = m_1.Length;33 if (m_1.IndexOf(‘.‘) > 0)34 iLen = m_1.IndexOf(‘.‘);//获取整数位数35 for (int j = iLen; j >= 1; j--)36 m_3 += numChinaWeigh.Substring(j - 1, 1);37 //m_4:2行+3行38 for (int i = 0; i < m_3.Length; i++)39 m_4 += m_2.Substring(i, 1) + m_3.Substring(i, 1);40 //m_5:4行去"0"后拾佰仟41 m_5 = m_4;42 m_5 = m_5.Replace("零拾", "零");43 m_5 = m_5.Replace("零佰", "零");44 m_5 = m_5.Replace("零仟", "零");45 //m_6:00-> 0,000-> 046 m_6 = m_5;47 for (int i = 0; i < iLen; i++)48 m_6 = m_6.Replace("零零", "零");49 //m_7:6行去亿,万,个位"0"50 m_7 = m_6;51 m_7 = m_7.Replace("亿零万零", "亿零");52 m_7 = m_7.Replace("亿零万", "亿零");53 m_7 = m_7.Replace("零亿", "亿");54 m_7 = m_7.Replace("零万", "万");55 if (m_7.Length > 2)56 m_7 = m_7.Replace("零个", "个");57 //m_8:7行+2行小数-> 数目58 m_8 = m_7;59 m_8 = m_8.Replace("个", "");60 if (m_2.Substring(m_2.Length - 3, 3) != "点零零")61 m_8 += m_2.Substring(m_2.Length - 3, 3);62 //m_9:7行+2行小数-> 价格63 m_9 = m_7;64 m_9 = m_9.Replace("个", "圆");65 if (m_2.Substring(m_2.Length - 3, 3) != "点零零")66 {67 m_9 += m_2.Substring(m_2.Length - 2, 2);68 m_9 = m_9.Insert(m_9.Length - 1, "角");69 m_9 += "分";70 }71 else m_9 += "整";72 if (m_9 != "零圆整")73 m_9 = m_9.Replace("零圆", "");74 m_9 = m_9.Replace("零分", "整");75 if (type == "数量")76 return m_8;77 else78 return m_9;79 }80 catch (Exception ex)81 {82 return ex.Message;83 }84 #endregion85 }
C# 数字转换成大写
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。