C#将货币转换为大写的代码
/// <summary>
/// 将货币转化为大写形式,根据网上ASP程序改编
/// </summary>
/// <param name="num">货币数值,不能超过1亿,且形式为:xxx.xx</param>
/// <returns></returns>
public string ChineseRead2( double num )
{
string numList="", rmbList="", numstr="", n1="", n2="", hz="";
int n=0, numLen=0, numChar=0;
numList = "零壹贰叁肆伍陆柒捌玖";
rmbList = "分角元拾佰仟万拾佰仟亿拾佰仟万";
if( num > 99999999.99 )
{
return "超出范围的人民币值";
}
numstr = ( num * 100 ).ToString();
numLen = numstr.Length;
n = 0;
for( n = 0; n < numLen; n++ )
{
numChar = Convert.ToInt32( numstr.Substring( n, 1) );
n1 = numList.Substring( numChar, 1 );
n2 = rmbList.Substring( numLen - ( n + 1 ), 1 );
if( n1 != "零" )
{
hz = hz + n1 + n2;
}
else
{
if( n2 == "亿" || n2 == "万" || n2 == "元" || n1 == "零" )
{
while( hz.EndsWith( "零" ) )
{
hz = hz.Substring( 0, hz.Length - 1 );
}
}
if( n2 == "亿" || ( n2 == "万" && hz.EndsWith( "亿" ) ) || n2 == "元" )
{
hz = hz + n2;
}
else if( hz.Remove( hz.Length - 1, 1 ).EndsWith( "零" ) || !hz.EndsWith( "亿" ) )
{
hz = hz + n1;
}
}
}
while( hz.EndsWith( "零" ) )
{
hz = hz.Substring( 0, hz.Length - 1 );
}
if( hz.EndsWith( "元" ) )
{
hz = hz + "整";
}
return hz;
}
#endregion
您可能感兴趣的文章:
C#将货币转换为大写的代码
货币数字转换为中文大写的php代码
如何实现python汇率转换代码
PostgreSQL从菜鸟到专家系列教程(1)PostgreSQL介绍
C# 数字(英文)货币转换为大写的方法
php人民币小写转大写的函数,不限长度,精确到分(推荐)
javascript 格式化货币数据的代码
c# DataSet转为XML时格式化字段数据的方法
python入门题:输入输出练习
阿拉伯数字转中文数字的php自定义函数