关闭

数字金额转换成中文金额(C#实现)

718人阅读 评论(0) 收藏 举报
public static string ConvertNumAmtToChinese(decimal numVal)
  {
   decimal org = EMSMath.Round(numVal,2);
   string orgData = org.ToString();
   int length = orgData.Length;
   int j = 0;
   string ret = string.Empty;
   string temp = string.Empty;
   //9,123,456,789,123.12
   for (int i=length-1;i>=0;i--)
   {
    temp = "";
    j++;
    switch (orgData[i])
    {
     case '.' : temp = "元";
      break;
     case '0' : temp = "零";
      break;
     case '1' : temp = "壹";
      break;
     case '2' : temp = "贰";
      break;
     case '3' : temp = "叁";
      break;
     case '4' : temp = "肆";
      break;
     case '5' : temp = "伍";
      break;
     case '6' : temp = "陆";
      break;
     case '7' : temp = "柒";
      break;
     case '8' : temp = "捌";
      break;
     case '9' : temp = "玖";
      break;
     default : break;
    }
    switch(j)
    {
     case 1  : temp = temp + "分";
      break;
     case 2  : temp = temp + "角";
      break;
     case 3  : temp = temp + "";
      break;
     case 4  : temp = temp + "";
      break;
     case 5  : temp = temp + "拾";
      break;
     case 6  : temp = temp + "佰";
      break;
     case 7  : temp = temp + "仟";
      break;
     case 8  : temp = temp + "万";
      break;
     case 9  : temp = temp + "拾";
      break;
     case 10 : temp = temp + "佰";
      break;
     case 11 : temp = temp + "仟";
      break;
     case 12 : temp = temp + "亿";
      break;
     case 13 : temp = temp + "拾";
      break;
     case 14 : temp = temp + "佰";
      break;
     case 15 : temp = temp + "仟";
      break;
     case 16 : temp = temp + "万";
      break;
     default: break;
    }    
    ret = temp + ret;
   }
   
   ret = ret.Replace("零拾","零");
   ret = ret.Replace("零佰","零");
   ret = ret.Replace("零仟","零");
   ret = ret.Replace("零零零","零");
   ret = ret.Replace("零零","零");
   ret = ret.Replace("零角零分","整");
   ret = ret.Replace("零分","整");
   ret = ret.Replace("零分","整");
   ret = ret.Replace("零亿零万零元","亿元");
   ret = ret.Replace("亿零万零元","亿元");
   ret = ret.Replace("零亿零万","亿");
   ret = ret.Replace("零万零元","万元");
   ret = ret.Replace("万零元","万元");
   ret = ret.Replace("零亿","亿");
   ret = ret.Replace("零万","万");
   ret = ret.Replace("零元","元");
   ret = ret.Replace("零零","零");
   return ret;
  }
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:30741次
    • 积分:566
    • 等级:
    • 排名:千里之外
    • 原创:20篇
    • 转载:3篇
    • 译文:0篇
    • 评论:8条
    最新评论