金额转换成大写(从Sql Server版转换成的C#版)
2007-05-15 19:52
543 查看
namespace AA
{
public class BB
{
public static string L2U(decimal lowerMoney)
{
string lowerStr = string.Empty;
string upperPart = string.Empty;
string upperStr = string.Empty;
lowerStr = lowerMoney.ToString("F2");
for (int index = 0; index < lowerStr.Length; index++)
{
upperPart = GetUpperNumber(lowerStr.Substring(lowerStr.Length - index-1, 1))
+ GetUnit(index+1);
upperStr = upperPart + upperStr;
}
upperStr = upperStr.Replace("零拾", "零");
upperStr = upperStr.Replace("零佰", "零");
upperStr = upperStr.Replace("零仟", "零");
upperStr = upperStr.Replace("零零零", "零");
upperStr = upperStr.Replace("零零", "零");
upperStr = upperStr.Replace("零角零分", "整");
upperStr = upperStr.Replace("零分", "整");
upperStr = upperStr.Replace("零角", "零");
upperStr = upperStr.Replace("零亿零万零元", "亿元");
upperStr = upperStr.Replace("亿零万零元", "亿元");
upperStr = upperStr.Replace("零亿零万", "亿");
upperStr = upperStr.Replace("零万零元", "万元");
upperStr = upperStr.Replace("万零元", "万元");
upperStr = upperStr.Replace("零亿", "亿");
upperStr = upperStr.Replace("零万", "万");
upperStr = upperStr.Replace("零元", "元");
upperStr = upperStr.Replace("零零", "零");
if ("元" == upperStr.Substring(0, 1))
{
upperStr = upperStr.Substring(1, upperStr.Length - 1);
}
if ("零" == upperStr.Substring(0, 1))
{
upperStr = upperStr.Substring(1, upperStr.Length - 1);
}
if ("角" == upperStr.Substring(0, 1))
{
upperStr = upperStr.Substring(1, upperStr.Length - 1);
}
if ("分" == upperStr.Substring(0, 1))
{
upperStr = upperStr.Substring(1, upperStr.Length - 1);
}
if ("整" == upperStr.Substring(0, 1))
{
upperStr = "零元整";
}
if ("壹拾" == upperStr.Substring(0, 2))
{
upperStr = upperStr.Substring(1, upperStr.Length - 1);
}
return upperStr;
}
private static string GetUpperNumber(string str)
{
string cstr = string.Empty;
switch (str)
{
case ".": cstr = "元"; break;
case "0": cstr = "零"; break;
case "1": cstr = "壹"; break;
case "2": cstr = "贰"; break;
case "3": cstr = "叁"; break;
case "4": cstr = "肆"; break;
case "5": cstr = "伍"; break;
case "6": cstr = "陆"; break;
case "7": cstr = "柒"; break;
case "8": cstr = "捌"; break;
case "9": cstr = "玖"; break;
}
return cstr;
}
private static string GetUnit(int index)
{
string cstr;
switch (index)
{
case 1: cstr = "分"; break;
case 2: cstr = "角"; break;
case 3: cstr = ""; break;
case 4: cstr = ""; break;
case 5: cstr = "拾"; break;
case 6: cstr = "佰"; break;
case 7: cstr = "仟"; break;
case 8: cstr = "万"; break;
case 9: cstr = "拾"; break;
case 10: cstr = "佰"; break;
case 11: cstr = "仟"; break;
case 12: cstr = "亿"; break;
case 13: cstr = "拾"; break;
case 14: cstr = "佰"; break;
case 15: cstr = "仟"; break;
case 16: cstr = "万"; break;
default: cstr = ""; break;
}
return cstr;
}
}
}
{
public class BB
{
public static string L2U(decimal lowerMoney)
{
string lowerStr = string.Empty;
string upperPart = string.Empty;
string upperStr = string.Empty;
lowerStr = lowerMoney.ToString("F2");
for (int index = 0; index < lowerStr.Length; index++)
{
upperPart = GetUpperNumber(lowerStr.Substring(lowerStr.Length - index-1, 1))
+ GetUnit(index+1);
upperStr = upperPart + upperStr;
}
upperStr = upperStr.Replace("零拾", "零");
upperStr = upperStr.Replace("零佰", "零");
upperStr = upperStr.Replace("零仟", "零");
upperStr = upperStr.Replace("零零零", "零");
upperStr = upperStr.Replace("零零", "零");
upperStr = upperStr.Replace("零角零分", "整");
upperStr = upperStr.Replace("零分", "整");
upperStr = upperStr.Replace("零角", "零");
upperStr = upperStr.Replace("零亿零万零元", "亿元");
upperStr = upperStr.Replace("亿零万零元", "亿元");
upperStr = upperStr.Replace("零亿零万", "亿");
upperStr = upperStr.Replace("零万零元", "万元");
upperStr = upperStr.Replace("万零元", "万元");
upperStr = upperStr.Replace("零亿", "亿");
upperStr = upperStr.Replace("零万", "万");
upperStr = upperStr.Replace("零元", "元");
upperStr = upperStr.Replace("零零", "零");
if ("元" == upperStr.Substring(0, 1))
{
upperStr = upperStr.Substring(1, upperStr.Length - 1);
}
if ("零" == upperStr.Substring(0, 1))
{
upperStr = upperStr.Substring(1, upperStr.Length - 1);
}
if ("角" == upperStr.Substring(0, 1))
{
upperStr = upperStr.Substring(1, upperStr.Length - 1);
}
if ("分" == upperStr.Substring(0, 1))
{
upperStr = upperStr.Substring(1, upperStr.Length - 1);
}
if ("整" == upperStr.Substring(0, 1))
{
upperStr = "零元整";
}
if ("壹拾" == upperStr.Substring(0, 2))
{
upperStr = upperStr.Substring(1, upperStr.Length - 1);
}
return upperStr;
}
private static string GetUpperNumber(string str)
{
string cstr = string.Empty;
switch (str)
{
case ".": cstr = "元"; break;
case "0": cstr = "零"; break;
case "1": cstr = "壹"; break;
case "2": cstr = "贰"; break;
case "3": cstr = "叁"; break;
case "4": cstr = "肆"; break;
case "5": cstr = "伍"; break;
case "6": cstr = "陆"; break;
case "7": cstr = "柒"; break;
case "8": cstr = "捌"; break;
case "9": cstr = "玖"; break;
}
return cstr;
}
private static string GetUnit(int index)
{
string cstr;
switch (index)
{
case 1: cstr = "分"; break;
case 2: cstr = "角"; break;
case 3: cstr = ""; break;
case 4: cstr = ""; break;
case 5: cstr = "拾"; break;
case 6: cstr = "佰"; break;
case 7: cstr = "仟"; break;
case 8: cstr = "万"; break;
case 9: cstr = "拾"; break;
case 10: cstr = "佰"; break;
case 11: cstr = "仟"; break;
case 12: cstr = "亿"; break;
case 13: cstr = "拾"; break;
case 14: cstr = "佰"; break;
case 15: cstr = "仟"; break;
case 16: cstr = "万"; break;
default: cstr = ""; break;
}
return cstr;
}
}
}
相关文章推荐
- C# 实现将阿拉伯数字转换成中文大写金额
- C#实现阿拉伯数字(小写金额)到大写中文(大写金额)的转换
- C#把数字转换为大写金额
- sql server 关于表中只增标识问题 C# 实现自动化打开和关闭可执行文件(或 关闭停止与系统交互的可执行文件) ajaxfileupload插件上传图片功能,用MVC和aspx做后台各写了一个案例 将小写阿拉伯数字转换成大写的汉字, C# WinForm 中英文实现, 国际化实现的简单方法 ASP.NET Core 2 学习笔记(六)ASP.NET Core 2 学习笔记(三)
- C#金额转换为汉字大写
- Expression构建DataTable to Entity 映射委托 sqlserver 数据库里面金额类型为什么不建议用float,实例告诉你为什么不能。 sql server 多行数据合并成一列 C# 字符串大写转小写,小写转大写,数字保留,其他除外 从0开始用U盘制作启动盘装Windows10系统(联想R720笔记本)并永久激活方法 纯CSS打造淘宝导航菜单栏 C# Winform
- C#转换人民币大写金额
- Sql Server 小写金额转换成大写
- C#阿拉伯数字金额转换为中文大写金额
- C#中将小写金额转换为大写金额
- C#小写数字金额转换成大写人民币金额的算法
- C#金额转换为汉字大写
- C#实现的【阿拉伯数字转换成中文大写金额】
- 在C#中将金额转换成中文大写金额
- C#中利用正则表达式将人民币金额转换为大写汉字
- C#把数字转换成大写金额的代码实例
- c#金额转换成中文大写金额
- C# 金额转换繁体大写
- 小写数字金额转换成大写金额(C#)
- 浮点数金额转换成大写人民币表示(C#)