数字金额转换大写人民币
Posted Asp.NET开发
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了数字金额转换大写人民币相关的知识,希望对你有一定的参考价值。
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 "转换失败!";
}
}
}
}
以上是关于数字金额转换大写人民币的主要内容,如果未能解决你的问题,请参考以下文章