失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > 阿拉伯数字转换成人民币大写金额的方法

阿拉伯数字转换成人民币大写金额的方法

时间:2021-12-19 22:51:29

相关推荐

阿拉伯数字转换成人民币大写金额的方法

public static string chang(decimal money){money = Math.Round(money, 2);string moneyStr = money.ToString();String[] myBase = {"零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" };var myScale=new Dictionary<int, string>{{-2, "分"},{-1, "角"},{1, "元"},{2, "拾"},{3, "佰"},{4, "仟"},{5, "万"},{6, "拾"},{7, "佰"},{8, "仟"},{9, "亿"},{10, "拾"},{11, "佰"},{12, "仟"}};String result = "";//小写金额格式必须是123.00或者123.40这种if (moneyStr.IndexOf(".") == -1){moneyStr += ".00";}else if(moneyStr.Length-(moneyStr.IndexOf(".")+1)==1){moneyStr += "0";}int pointIndex = moneyStr.IndexOf(".");bool skipZero = false;//整数部分for (int i = 0; i < moneyStr.Length; i++){if (i == pointIndex){break;}//数字int tempInt = Convert.ToInt32(moneyStr.Substring(i,1));if (tempInt!=0){if (skipZero){result += "零";skipZero = false;}result += myBase[tempInt];}else{skipZero=true;}//数量级switch (pointIndex - i){case 9:case 5: result += myScale.First(p => p.Key == pointIndex - i).Value;break;case 1:if (money<1){result +=""; }else{result += myScale.First(p => p.Key == pointIndex - i).Value; }break;default:if (tempInt != 0 ){result += myScale.First(p => p.Key == pointIndex - i).Value;}break;}}//小数部分for (int i = pointIndex + 1; i <= pointIndex+2; i++){//数字int tempInt = Convert.ToInt32(moneyStr.Substring(i, 1));if (tempInt != 0){result += myBase[tempInt];}//数量级if (tempInt != 0){result += myScale.First(p => p.Key == pointIndex - i).Value;}}if (!result.Contains("角")&&!result.Contains("分")){result += "整";}//特殊的0.00,不符合一般的规律if (money==0){result = "零元整";}return result;}

如果觉得《阿拉伯数字转换成人民币大写金额的方法》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。