最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
asp.net 可达千百万亿 人民币小写转大写金额
时间:2011-03-16 编辑:简简单单 来源:一聚教程网
asp教程.net 可达千百万亿 人民币小写转大写金额
///
/// 小写金额转换成大写金额
///
///
///
///
public static string converttochnmoney(decimal number, chnmoneytype turntype)
{
string s_chnnumstring = "零壹贰叁肆伍陆柒捌玖";
//可正确最大金额可以到千万亿元正,有分位为百万亿元或十万亿
string result = string.empty;
if (number > 0)
{
string s_dxdw = "分角元拾佰仟万拾佰仟亿拾佰仟万拾佰仟";
ulong je = (ulong)(number * 100);
ulong temnum = je;
int index = 0;
for (int n = 0; temnum != 0; n++)
{
index = (int)(temnum - temnum / 10 * 10); //取出最后一个数
temnum = temnum / 10;
result = s_chnnumstring.substring(index, 1) + s_dxdw.substring(n, 1) + result; //发票格式
}
if (turntype == chnmoneytype.checktype)
{
string temresult = string.empty;
string temmoney = string.empty;
string unit = string.empty;
string digitchar = string.empty;
string str1 = "零元万整";
string str2 = "零元万亿整";
for (int n = result.length - 2; n >= 0; n = n - 2) //从后面每二个取字符串。
{
temmoney = result.substring(n, 2);
unit = temmoney.substring(1, 1);
digitchar = temmoney.substring(0, 1);
switch (unit)
{
case "分":
if (digitchar == "零")
temmoney = "整";
break;
case "元":
case "万":
case "亿":
string temdigitchar = temresult.substring(0, 1);
if (digitchar == "零")
{
if (str1.indexof(temdigitchar) == -1)
temmoney = unit + "零";
else
{
if (temdigitchar == "万")
temresult = temresult.substring(1);
temmoney = unit;
}
}
else if (temdigitchar == "万")
temresult = temresult.substring(1);
break;
default:
if (digitchar == "零")
{
if (str2.indexof(temresult.substring(0, 1)) != -1)
temmoney = "";
else
temmoney = "零";
}
break;
}
temresult = temmoney + temresult;
}
result = temresult;
}
}
return result;
}
}
///
/// 大字金额的格式。
///
public enum chnmoneytype
{
///
/// 支票格式
///
checktype,
///
/// 发票格式
///
invoicetype
}
相关文章
- C#复制数组的两种方式及效率比较解读 10-24
- ASP.NET Identity用法解析 10-24
- ASP.NET MVC使用Identity增删改查用户介绍 10-24
- C语言中atoi函数模拟实现介绍 10-18
- .Net反向代理组件Yarp用法介绍 10-10
- .NET使用YARP通过编码方式配置域名转发实现反向代理教程 10-10