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

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;
  }
阅读更多
文章标签: c# string
个人分类: C#技术(C/S)
上一篇数字金额转换成中文金额(数据库实现)
下一篇最爱你的男孩
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭