财务中经常会用到数字大写的情况,本文介绍在C#如何将数字转变成大写。
例如1234567.89,转变成大写就是 壹佰贰拾叁万肆仟伍佰陆拾柒元捌角玖分
调用方法:
decimal
a
=
1234567.89M
;
string str = Utility.Finance.ConvertToCn(a);
string str = Utility.Finance.ConvertToCn(a);
转换类如下:
using
System;
using System.Collections.Generic;
using System.Text;
namespace Utility
{
public class Finance
{
public static string ConvertToCn( decimal num)
{
string str1 = " 零壹贰叁肆伍陆柒捌玖 " ; // 0-9所对应的汉字
string str2 = " 万仟佰拾亿仟佰拾万仟佰拾元角分 " ; // 数字位所对应的汉字
string str3 = "" ; // 从原num值中取出的值
string str4 = "" ; // 数字的字符串形式
string str5 = "" ; // 人民币大写金额形式
int i; // 循环变量
int j; // num的值乘以100的字符串长度
string ch1 = "" ; // 数字的汉语读法
string ch2 = "" ; // 数字位的汉字读法
int nzero = 0 ; // 用来计算连续的零值是几个
int temp; // 从原num值中取出的值
num = Math.Round(Math.Abs(num), 2
using System.Collections.Generic;
using System.Text;
namespace Utility
{
public class Finance
{
public static string ConvertToCn( decimal num)
{
string str1 = " 零壹贰叁肆伍陆柒捌玖 " ; // 0-9所对应的汉字
string str2 = " 万仟佰拾亿仟佰拾万仟佰拾元角分 " ; // 数字位所对应的汉字
string str3 = "" ; // 从原num值中取出的值
string str4 = "" ; // 数字的字符串形式
string str5 = "" ; // 人民币大写金额形式
int i; // 循环变量
int j; // num的值乘以100的字符串长度
string ch1 = "" ; // 数字的汉语读法
string ch2 = "" ; // 数字位的汉字读法
int nzero = 0 ; // 用来计算连续的零值是几个
int temp; // 从原num值中取出的值
num = Math.Round(Math.Abs(num), 2