1001000读作一百万一千
如果划线部分去掉则
1001000读作一百万○一千
public static string CmycurD(decimal num) { string strNum = "○一二三四五六七八九"; //0-9所对应的汉字 string strUnit = "万千百十亿千百十万千百十 "; //数字位所对应的汉字 string strGet = ""; //从原num值中取出的值 string strTurn = ""; //数字的字符串形式 string strOut = ""; //人民币大写金额形式 int i; //循环变量 int j; //num的值乘以100的字符串长度 string ch1 = ""; //数字的汉语读法 string ch2 = ""; //数字位的汉字读法 int nzero = 0; //用来计算连续的零值是几个 int intTemp; //从原num值中取出的值 //num = Math.Round(Math.Abs(num), 2); //将num取绝对值并四舍五入取2位小数 num = Math.Round(num, 0); //str4 = ((long)(num * 100)).ToString(); //将num乘100并转换成字符串形式 strTurn = ((long)num).ToString(); j = strTurn.Length; //找出最高位 if (j > 12) { return "溢出"; } strUnit = strUnit.Substring(13 - j); //取出对应位数的str2的值。如:200.55,j为5所以str2=佰拾元角分 //循环取出每一位需要转换的值 for (i = 0; i < j; i++) { strGet = strTurn.Substring(i, 1); //取出需转换的某一位的值 intTemp = Convert.ToInt32(strGet); //转换为数字 //if (i != (j - 1) && i != (j - 5) && i != (j - 9)) { //当所取位数不为个、万、亿、万亿上的数字时 if (strGet == "0")//如果是0 { ch1 = ""; ch2 = ""; nzero = nzero + 1; } else { if (nzero != 0)//如果计数>0 { ch1 = "○" + strNum.Substring(intTemp, 1); } else { ch1 = strNum.Substring(intTemp, 1); } ch2 = strUnit.Substring(i, 1); nzero = 0; } } if (i == (j - 9) || i == (j - 5)) { //如果该位是亿位或元位,则必须写上 ch2 = strUnit.Substring(i, 1); if (nzero<4) nzero = 0; } strOut = strOut + ch1 + ch2; } strOut = (strOut.Substring(0, 2).Replace("一十", "十") + strOut.Substring(2)).Replace("亿万", "亿"); return strOut; }
原文地址:https://www.cnblogs.com/hardenzhao/p/12264205.html
时间: 2024-11-05 20:47:51