• 把数字金额转换成人民币大写[原创]


    最近在用这个博客,感觉博客园不错,以前用的是新浪的,感觉这个更好,所以好多东西现在转到这边来了。
    下面是一个数字转人民币大写的类,不啰嗦了,下面是代码:

     1  /// <summary>
     2  /// 把数字金额转换成人民币大写
     3  /// </summary>
     4  /// <param name="DataInput">要转换的数字金额</param>
     5  /// <param name="DisplayZero">是否显示全部零</param>
     6  /// <returns></returns>

     7  public string  DaXieMoney(double  DataInput,bool DisplayZero)
     8  {
     9   //将数值转换为大写金额
    10   //18个单位
    11   int overOp;
    12   string []StrScale ={"","","","","","","","","","","亿","","","","","","",""};
    13   //10个数字
    14   string []StrNumber ="","","""","","","","","",""};
    15   string Temp=DataInput.ToString();
    16   // 当小数点不存在或只有一位小数时的处理
    17   if(Temp.IndexOf(".")==-1)
    18    overOp=2;
    19   else
    20    overOp=Temp.IndexOf(".")+3-Temp.Length;
    21   // 如果小数位超出三位小数则不处理
    22   if(overOp<0)
    23    return "只能精确到分.";
    24   //去掉小数点
    25   string  StrTemp=Temp.Replace(".","");
    26   string StrResult = "";
    27   for (int i = StrTemp.Length; i > 0; i--)
    28   {
    29    StrResult += StrNumber[Convert.ToInt16(StrTemp[StrTemp.Length-i].ToString())];  
    30    StrResult += StrScale[i-1+overOp];    
    31   }

    32   // 当要求显示零时可以直接返回字符串。
    33   if(DisplayZero==true)
    34    return StrResult;
    35   // 去掉多余的零,以便符合语法规则。
    36   StrResult=StrResult.Replace("零仟","");
    37   StrResult=StrResult.Replace("零佰","");
    38   StrResult=StrResult.Replace("零拾","");
    39   StrResult=StrResult.Replace("零零零零元","");
    40   StrResult=StrResult.Replace("零零零零万","");
    41   StrResult=StrResult.Replace("零零零零亿","");
    42   StrResult=StrResult.Replace("零零零零兆","");
    43   StrResult=StrResult.Replace("零零零","");
    44   StrResult=StrResult.Replace("零零","");
    45   StrResult=StrResult.Replace("零元","");
    46   StrResult=StrResult.Replace("零万","");
    47   StrResult=StrResult.Replace("零亿","亿");
    48   StrResult=StrResult.Replace("零兆","");
    49   return StrResult;
    50  }

    51
  • 相关阅读:
    MongoDB ObjectId
    MongoDB固定集合
    MongoDB 正则表达式
    MongoDB Map Reduce
    MongoDB操作
    VIM跳到指定行
    linux之echo命令
    rpm and yum commands
    CentOS 7 下的软件安装建议
    apt系统中sources.list文件的解析
  • 原文地址:https://www.cnblogs.com/winnxm/p/911127.html
Copyright © 2020-2023  润新知