数字人民币(RMB)转化为大写汉字表达

using System.Text;

/// <summary>
/// ToChineseValue 的摘要说明
/// 人民币(RMB)转化为大写字母 
/// </summary>
public class ToChineseValue
{
    private enum chineseChar { 零, 壹, 贰, 叁, 肆, 伍, 陆, 柒, 捌, 玖 };
    private enum charValue { 个 = 1, 十, 百, 千 };
    private enum c { 元 = 1, 万, 亿, 兆 };
    private enum afterPoint { 角, 分 };

public ToChineseValue()
    {
        //
        // TODO: 在此处添加构造函数逻辑
        //
    }
    public static string toChineseChar(decimal d)
    {
        decimal flag = 0;
        if (d < 0)
        {
            flag = d;
            d = -d;
        }

string strChinese = "";
        string nextString = "";

System.Globalization.NumberFormatInfo fmat = new System.Globalization.NumberFormatInfo();
        fmat.CurrencyDecimalDigits = 2;
        fmat.CurrencySymbol = "";
        fmat.CurrencyGroupSizes = new int[] { 4, 4, 4, 4 };
        fmat.CurrencyGroupSeparator = ",";

string strx = d.ToString("c", fmat);
        string[] afterArray = strx.ToString().Split(‘.‘);

char[] prePoint = afterArray[0].ToCharArray();
        char[] nextChar = afterArray[1].ToCharArray();

if (System.Convert.ToDecimal(afterArray[0].ToString()) == 0)
        { strChinese = ""; }
        else
        {
            string[] str = afterArray[0].ToString().Split(‘,‘);
            int Num = str.Length;
            //交错数组用来放四个一组的数组
            char[][] part = new char[Num][];
            for (int i = 0; i < str.Length; i++)
            {
                part[i] = str[i].ToCharArray();
            }
            for (int i = 0; i < Num; i++)
            {
                for (int j = 0; j < part[i].Length; j++)
                {
                    //用枚举完成汉字的转换
                    strChinese += ((chineseChar)int.Parse(part[i][j].ToString())).ToString();
                    //用枚举完成单位: 个 十 百 千 
                    strChinese += ((charValue)(part[i].Length - j)).ToString();
                }
                //以下为处理元 万 亿 兆 
                strChinese += ((c)(part.Length - i)).ToString();
            }
        }
        //处理点号后面的小数部分        
        if (System.Convert.ToDecimal(afterArray[1].ToString()) == 0 && System.Convert.ToDecimal(afterArray[0].ToString()) != 0)
        {
            nextString = "整";
        }
        else
        {
            for (int i = 0; i < 2; i++)
            {
                int t = int.Parse(nextChar[i].ToString());
                nextString += ((chineseChar)int.Parse(nextChar[i].ToString())).ToString();
                nextString += ((afterPoint)(i)).ToString();
                if (t == 0)
                {
                    StringBuilder str = new StringBuilder(nextString);
                    nextString = str.Replace("零零", "零").ToString();
                    nextString = str.Replace("零角零分", "零元").ToString();
                }
            }
        }
        StringBuilder sb = new StringBuilder(strChinese);
        for (int i = 0; i < 4; i++)
        {
            strChinese = sb.Replace("个", "").ToString();
            strChinese = sb.Replace("零元", "元").ToString();
            strChinese = sb.Replace("零万", "万").ToString();
            strChinese = sb.Replace("亿万", "亿").ToString();
            strChinese = sb.Replace("零亿", "亿").ToString();
            strChinese = sb.Replace("零十", "零").ToString();
            strChinese = sb.Replace("零百", "零").ToString();
            strChinese = sb.Replace("零千", "零").ToString();
            strChinese = sb.Replace("零零", "零").ToString();
            strChinese = sb.Replace("零角零分", "整").ToString();
        }
        if (flag >= 0)
        {
            return strChinese + nextString;
        }
        return "负" + strChinese + nextString;
    }
}

原文地址:https://www.cnblogs.com/jnhe/p/9529017.html

时间: 2024-10-05 04:55:15

数字人民币(RMB)转化为大写汉字表达的相关文章

用python实现把数字人民币金额转换成大写的脚本程序

# -*- coding: utf-8 -*- def Num2MoneyFormat( change_number ): """ .转换数字为大写货币格式( format_word.__len__() - 3 + 2位小数 ) change_number 支持 float, int, long, string """ format_word = ["分", "角", "元", &quo

将金额数字转换为大写汉字的js函数

1 //将金额数字转换为大写汉字的函数 2 function convertCurrency(money) { 3 //汉字的数字 4 var cnNums = new Array('零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'); 5 //基本单位 6 var cnIntRadice = new Array('', '拾', '佰', '仟'); 7 //对应整数部分扩展单位 8 var cnIntUnits = new Array('', '

人民币数值转中文大写

class Num2RmbClass{ /** * 人民币数值转中文大写 * @author SunsCheung * @time 2015.11.11 * @param string $number 数值 默认为0 * @param string $int_unit 币种单位,默认"元",有的需求可能为"圆" * @param bool $is_round 是否对小数进行四舍五入 * @param bool $is_extra_zero 是否对整数部分以0结尾,小

java_js_method实现输入小写字母自动转化成大写的代码实例

方法一: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Con

将字符串中的三个单词的首字母转化成大写

<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Title</title> <script> //var a = 'welcome to china'; //将字符串中的三个单词的首字母转化成大写:返回Welcome To China; var a = 'welcome to china'; va

将金额人民币转化为大写

/// <summary> /// 转换人民币大小金额 /// </summary> /// <param name="num">金额</param> /// <returns>返回大写形式</returns> public static string CmycurD(decimal num) { string str1 = "零壹贰叁肆伍陆柒捌玖"; //0-9所对应的汉字 string st

SSRS 实现数字金额转换为中文大写汉字

比如: 金额=49,701,120.00,将其转换为"肆仟玖佰柒拾万壹仟壹佰贰拾元整":金额 289,546.52 ,转换为 "贰拾捌万玖仟伍佰肆拾陆元伍角贰分". 解决方法:添加VB的转换函数写在CODE里,然后在表达式里调用自定义函数转换. 如:增加两个占位符表达式,如小数位为0时表达式2添加"整", 表达式1=Code.GetCnString(Fields!Amount.Value) 表达式2=IIF(Fields!Amount.Value

0到9的数字替换成零 到 玖 的 大写汉字的函数

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

数字金额转大写汉字

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