zoukankan      html  css  js  c++  java
  • C#中金额的大小写转换

            public static string MoneyToUpper(string strAmount)
            {
               
    string functionReturnValue =null;
               
    bool IsNegative =false; // 是否是负数
                if (strAmount.Trim().Substring(0, 1) =="-")
                {
                   
    // 是负数则先转为正数
                    strAmount = strAmount.Trim().Remove(0, 1);
                    IsNegative
    =true;
                }
               
    string strLower =null;
               
    string strUpart =null;
               
    string strUpper =null;
               
    int iTemp =0;
               
    // 保留两位小数 123.489→123.49  123.4→123.4
                strAmount = Math.Round(double.Parse(strAmount), 2).ToString();
               
    if (strAmount.IndexOf(".") >0)
                {
                   
    if (strAmount.IndexOf(".") == strAmount.Length -2)
                    {
                        strAmount
    = strAmount +"0";
                    }
                }
               
    else
                {
                    strAmount
    = strAmount +".00";
                }
                strLower
    = strAmount;
                iTemp
    =1;
                strUpper
    ="";
               
    while (iTemp <= strLower.Length)
                {
                   
    switch (strLower.Substring(strLower.Length - iTemp, 1))
                    {
                       
    case".":
                            strUpart
    ="";
                           
    break;
                       
    case"0":
                            strUpart
    ="";
                           
    break;
                       
    case"1":
                            strUpart
    ="";
                           
    break;
                       
    case"2":
                            strUpart
    ="";
                           
    break;
                       
    case"3":
                            strUpart
    ="";
                           
    break;
                       
    case"4":
                            strUpart
    ="";
                           
    break;
                       
    case"5":
                            strUpart
    ="";
                           
    break;
                       
    case"6":
                            strUpart
    ="";
                           
    break;
                       
    case"7":
                            strUpart
    ="";
                           
    break;
                       
    case"8":
                            strUpart
    ="";
                           
    break;
                       
    case"9":
                            strUpart
    ="";
                           
    break;
                    }

                   
    switch (iTemp)
                    {
                       
    case1:
                            strUpart
    = strUpart +"";
                           
    break;
                       
    case2:
                            strUpart
    = strUpart +"";
                           
    break;
                       
    case3:
                            strUpart
    = strUpart +"";
                           
    break;
                       
    case4:
                            strUpart
    = strUpart +"";
                           
    break;
                       
    case5:
                            strUpart
    = strUpart +"";
                           
    break;
                       
    case6:
                            strUpart
    = strUpart +"";
                           
    break;
                       
    case7:
                            strUpart
    = strUpart +"";
                           
    break;
                       
    case8:
                            strUpart
    = strUpart +"";
                           
    break;
                       
    case9:
                            strUpart
    = strUpart +"";
                           
    break;
                       
    case10:
                            strUpart
    = strUpart +"";
                           
    break;
                       
    case11:
                            strUpart
    = strUpart +"";
                           
    break;
                       
    case12:
                            strUpart
    = strUpart +"亿";
                           
    break;
                       
    case13:
                            strUpart
    = strUpart +"";
                           
    break;
                       
    case14:
                            strUpart
    = strUpart +"";
                           
    break;
                       
    case15:
                            strUpart
    = strUpart +"";
                           
    break;
                       
    case16:
                            strUpart
    = strUpart +"";
                           
    break;
                       
    default:
                            strUpart
    = strUpart +"";
                           
    break;
                    }

                    strUpper
    = strUpart + strUpper;
                    iTemp
    = iTemp +1;
                }

                strUpper
    = strUpper.Replace("零拾", "");
                strUpper
    = strUpper.Replace("零佰", "");
                strUpper
    = strUpper.Replace("零仟", "");
                strUpper
    = strUpper.Replace("零零零", "");
                strUpper
    = strUpper.Replace("零零", "");
                strUpper
    = strUpper.Replace("零角零分", "");
                strUpper
    = strUpper.Replace("零分", "");
                strUpper
    = strUpper.Replace("零角", "");
                strUpper
    = strUpper.Replace("零亿零万零圆", "亿圆");
                strUpper
    = strUpper.Replace("亿零万零圆", "亿圆");
                strUpper
    = strUpper.Replace("零亿零万", "亿");
                strUpper
    = strUpper.Replace("零万零圆", "万圆");
                strUpper
    = strUpper.Replace("零亿", "亿");
                strUpper
    = strUpper.Replace("零万", "");
                strUpper
    = strUpper.Replace("零圆", "");
                strUpper
    = strUpper.Replace("零零", "");

               
    // 对壹圆以下的金额的处理
                if (strUpper.Substring(0, 1) =="")
                {
                    strUpper
    = strUpper.Substring(1, strUpper.Length -1);
                }
               
    if (strUpper.Substring(0, 1) =="")
                {
                    strUpper
    = strUpper.Substring(1, strUpper.Length -1);
                }
               
    if (strUpper.Substring(0, 1) =="")
                {
                    strUpper
    = strUpper.Substring(1, strUpper.Length -1);
                }
               
    if (strUpper.Substring(0, 1) =="")
                {
                    strUpper
    = strUpper.Substring(1, strUpper.Length -1);
                }
               
    if (strUpper.Substring(0, 1) =="")
                {
                    strUpper
    ="零圆整";
                }
                functionReturnValue
    = strUpper;

               
    if (IsNegative ==true)
                {
                   
    return""+ functionReturnValue;
                }
               
    else
                {
                   
    return functionReturnValue;
                }
            }

  • 相关阅读:
    MDX函数
    OLAP + MDX
    AIOps指导
    ES Terms 聚合数据不确定性
    redis初步入门
    java写hadoop全局排序
    [工程技巧]
    python与字符集编码
    转载python2进制打包相关
    转载 大端VS小端
  • 原文地址:https://www.cnblogs.com/jsping/p/2607772.html
Copyright © 2011-2022 走看看