数字金额转换大写人民币

using System;
using System.Collections.Generic;
using System.Text;

namespace PublicClass
{
    /// <summary>
    /// Copyright(c) 2008~2011 KingBoy Software Co.,Ltd
    /// FileName:大写人民币类
    /// Author:KingBoy  Version:1.0.0.0  Date:2009-3-05
    /// Description:提供将数值型输入转变成人民币大写的标准类。 
    /// </summary>
    public class ChineseMoney
    {
        private decimal dMoney = 0; //金额
        /// <summary>
        /// 设置或获取金额
        /// </summary>
        public decimal money
        {
            get { return dMoney; }
            set { dMoney = value; }
        }
        public ChineseMoney(decimal m)
        {
            dMoney = m;
        }
        /// <summary>
        /// 获取金额大写
        /// </summary>
        /// <returns></returns>
        public string getChineseMoney()
        {
            try
            {
                string strcmd = Convert.ToString(dMoney); //将金额转换为字符串型
                string[] temp = strcmd.Split(‘.‘);
                string[] integer ={"元","拾","佰","仟","万","拾万","佰万","仟万","亿","拾亿","佰亿","仟亿","万亿","亿亿" };
                string[] infrex ={"角","分" };
                string[] data ={"零","壹","贰","叁","肆","伍","陆","柒","捌","玖" };
                string result = "";
                if (temp.Length > 0)
                {
                    /*
                     处理整数部分
                     */
                    string ch = "";
                    for (int i = 0; i < temp[0].Length; i++)
                    {
                        switch (Convert.ToInt32(temp[0].Substring(i, 1)))
                        {
                            case 0:
                                ch = data[0]; break;
                            case 1:
                                ch = data[1]; break;
                            case 2:
                                ch = data[2]; break;
                            case 3:
                                ch = data[3]; break;
                            case 4:
                                ch = data[4]; break;
                            case 5:
                                ch = data[5]; break;
                            case 6:
                                ch = data[6]; break;
                            case 7:
                                ch = data[7]; break;
                            case 8:
                                ch = data[8]; break;
                            case 9:
                                ch = data[9]; break;
                            default:
                                ch = ""; break;
                        }
                        if (Convert.ToInt32(temp[0].Substring(i, 1)) > 0)
                            result =  result+ ch +integer[temp[0].Length-i-1];
                        else
                            result = result +ch ;
                    }
                }
                  if (temp.Length > 1) //处理小数部分
                  { 
                     string ch = "";
                  for (int i = 0; i < temp[1].Length; i++)
                  {
                      switch (Convert.ToInt32(temp[1].Substring(i, 1)))
                      {
                          case 0:
                              ch = data[0]; break;
                          case 1:
                              ch = data[1]; break;
                          case 2:
                              ch = data[2]; break;
                          case 3:
                              ch = data[3]; break;
                          case 4:
                              ch = data[4]; break;
                          case 5:
                              ch = data[5]; break;
                          case 6:
                              ch = data[6]; break;
                          case 7:
                              ch = data[7]; break;
                          case 8:
                              ch = data[8]; break;
                          case 9:
                              ch = data[9]; break;
                          default:
                              ch = ""; break;
                      }
                      if (Convert.ToInt32(temp[1].Substring(i, 1)) > 0)
                          result =result+ch+infrex[i] ;
                      else
                          result = result +ch;
                  }

}
                return result;

}
            catch (Exception)
            {
                return "转换失败!";
            }
        }
    }
}

时间: 2024-10-11 00:00:38

数字金额转换大写人民币的相关文章

JS实现将数字金额转换为大写人民币汉字

function convertCurrency(money) { //汉字的数字 var cnNums = new Array('零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'); //基本单位 var cnIntRadice = new Array('', '拾', '佰', '仟'); //对应整数部分扩展单位 var cnIntUnits = new Array('', '万', '亿', '兆'); //对应小数部分单位 var cnDe

PHP数字金额转换大写金额

早些年做CRM用到的一个金额转换函数,今天从旧项目中拿出来记录一下.金额转换的函数方法有很多,都很不错.不过这个是小崔刚工作的时候写的一个转换函数,多少还是有点纪念意义.如有问题请朋友们指出,小崔及时修正.谢谢啦! 废话不多说直接上代码: 1 <?php 2 3 /** 4 * 数字金额转换大写数字 5 * $num 数字类型 6 */ 7 8 function inttodaxie($num) { 9 //判断$num是否数字 10 if(!is_numeric($num)) return -

PHP算法--将数字金额转换成大写金额

最近在看一些PHP算法题,遇到一个将数字金额转换成大写金额的小算法题,这里贴出自己的一个例子. 注:这个小算法适用于10万以内的金额. <?php //$num = 12345.67; function RMB_Upper($num) { $num = round($num,2); //取两位小数 $num = ''.$num; //转换成数字 $arr = explode('.',$num); $str_left = $arr[0]; // 12345 $str_right = $arr[1]

PHP 数字金额转换成中文大写金额的函数 数字转中文

/** *数字金额转换成中文大写金额的函数 *String Int $num 要转换的小写数字或小写字符串 *return 大写字母 *小数位为两位 **/ function num_to_rmb($num){ $c1 = "零壹贰叁肆伍陆柒捌玖"; $c2 = "分角元拾佰仟万拾佰仟亿"; //精确到分后面就不要了,所以只留两个小数位 $num = round($num, 2); //将数字转化为整数 $num = $num * 100; if (strlen($

数字金额转换中文大写

<script type="text/javascript" language="javascript">function Arabia_to_Chinese(Num){ for(i=Num.length-1;i>=0;i--) {  Num = Num.replace(",","")//替换tomoney()中的","  Num = Num.replace(" ",&

数字金额转大写汉字

function changeMoneyToChinese(money) { var cnNums = new Array("零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"); //汉字的数字 var cnIntRadice = new Array("

js金额转换大写

从tenpay找到的一段将金额小写转换成大写的js代码: 1 var DX = function (num) { 2 var strOutput = ""; 3 var strUnit = '仟佰拾亿仟佰拾万仟佰拾元角分'; 4 num += "00"; 5 var intPos = num.indexOf('.'); 6 if (intPos >= 0) 7 num = num.substring(0, intPos) + num.substr(intPos

java实现数字金额转换成汉字大写金额

我们经常在做项目的财务报表,需要打印发票等情况时需要用到小写的财务金额要转换成汉字的大写金额,下面就是实现该功能的代码 import java.lang.Math; /***通用型金钱转换类**/public class Money {  private String HanDigiStr[] = new String[] { "零", "壹", "贰", "叁", "肆", "伍", 

java 数字金额转换中文金额

public static String digitUppercase(double n){ String fraction[] = {"角", "分"}; String digit[] = { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", &q