C#将货币转换为大写的代码
本文导语: 代码示例: /// /// 将货币转化为大写形式,根据网上ASP程序改编 /// /// 货币数值,不能超过1亿,且形式为:xxx.xx /// public string ChineseRead2( double num ) { string numList="", rmbList="", numstr="", n1="", n2="", hz=""; int n=0, numLen=0, ...
///
/// 将货币转化为大写形式,根据网上ASP程序改编
///
/// 货币数值,不能超过1亿,且形式为:xxx.xx
///
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