您的位置:首页 > 编程语言 > C#

C#阿拉伯数字转换为中文大写

2008-12-01 15:52 573 查看
class ConvertNumber

{

#region 大写、单位数组定义

private static string[] cstr ={"零","壹","贰","叁","肆","伍","陆","柒","捌","玖" };

private static string[] wstr ={ "", "", "拾", "佰", "仟", "萬", "拾", "佰", "仟", "億", "拾", "佰", "仟" };

private static string[] lcstr ={ "〇", "一", "二", "三", "四", "五", "六", "七", "八", "九" };

#endregion

/// <summary>

/// 转换方法

/// </summary>

/// <param name="str">输入参数为阿拉伯数字</param>

/// <returns>返回字符串为中文大写</returns>

public static string ConvertInt(string str)

{

int len = str.Length;//获取字符串长度

int i;

string tmpstr, rstr;//rstr为返回的字符串

rstr = "";

//执行循环逐位分解字符串

for (i = 1; i <= len; i++)

{

tmpstr = str.Substring(len - i, 1);

rstr = string.Concat(cstr[Int32.Parse(tmpstr)] + wstr[i], rstr);

}

//当某位数值为零时进行替换

rstr = rstr.Replace("拾零", "拾");

rstr = rstr.Replace("零拾", "零");

rstr = rstr.Replace("零佰", "零");

rstr = rstr.Replace("零仟", "零");

rstr = rstr.Replace("零萬", "萬");

//当位数连续为零时进行替换

for (i = 1; i <= 6; i++)

rstr = rstr.Replace("零零", "零");

rstr = rstr.Replace("零萬", "零");

rstr = rstr.Replace("零億", "億");

rstr = rstr.Replace("零零", "零");

return rstr;

}

public static string ConvertDate(string str)

{

string tempStr=string .Empty ;

for (int i = 0; i < str.Length; i++)

{

tempStr = tempStr + lcstr[Int32.Parse(str.Substring(i, 1))];

}

return tempStr ;

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: