using System;
namespace Supersnake.Tools
{
/// <summary>
/// MoneyConverter 的摘要说明。
/// </summary>
public class MoneyConverter
{
private static string _uppers = "零壹贰叁肆伍陆柒捌玖";
private static string _units = "分角元拾佰仟万拾佰仟亿拾佰仟万";
/// <summary>
/// 转换成人民币大写形式
/// </summary>
/// <param name="money">人民币</param>
/// <returns>大写字串</returns>
public static string ToUpper(decimal money)
{
string sMoney = money.ToString("0.00").Replace(".","");
string sUpper = "";
int now;
for(int i = 0; i<sMoney.Length; i++)
{
now = sMoney[i] - '0';
sUpper += "" + _uppers[now] + _units[sMoney.Length - 1 - i];
}
return sUpper;
}
/// <summary>
/// 重载 转换成人民币大写形式
/// </summary>
/// <param name="strmoney">人民币</param>
/// <returns>大写字串</returns>
public static string ToUpper(string strmoney)
{
decimal money;
try
{
money = Convert.ToDecimal(strmoney);
}
catch(FormatException)
{
money = 0;
}
return ToUpper(money);
}
}
}
namespace Supersnake.Tools
{
/// <summary>
/// MoneyConverter 的摘要说明。
/// </summary>
public class MoneyConverter
{
private static string _uppers = "零壹贰叁肆伍陆柒捌玖";
private static string _units = "分角元拾佰仟万拾佰仟亿拾佰仟万";
/// <summary>
/// 转换成人民币大写形式
/// </summary>
/// <param name="money">人民币</param>
/// <returns>大写字串</returns>
public static string ToUpper(decimal money)
{
string sMoney = money.ToString("0.00").Replace(".","");
string sUpper = "";
int now;
for(int i = 0; i<sMoney.Length; i++)
{
now = sMoney[i] - '0';
sUpper += "" + _uppers[now] + _units[sMoney.Length - 1 - i];
}
return sUpper;
}
/// <summary>
/// 重载 转换成人民币大写形式
/// </summary>
/// <param name="strmoney">人民币</param>
/// <returns>大写字串</returns>
public static string ToUpper(string strmoney)
{
decimal money;
try
{
money = Convert.ToDecimal(strmoney);
}
catch(FormatException)
{
money = 0;
}
return ToUpper(money);
}
}
}