今天看到N多人Blog大写金额转换函数,我也来凑个热闹,顺便换个思路
using System;
namespace Excellent.Data
{
public sealed class Money
{
#region Variables
private const string UNIT = "分角元拾佰仟万拾佰仟亿拾佰仟万";
private const string UPPER = "零壹贰叁肆伍陆柒捌玖";
#endregion
#region Properties
#endregion
#region Constructors
#endregion
#region Overrides
#endregion
#region Methods
public static string GetUpper(decimal lower)
{
string stResult = "", stLower = "";
stLower = lower.ToString("0.00").Replace(".", "");
if (stLower.Length <= UNIT.Length)
{
for (int i = 0, j = stLower.Length - 1; i <= j; i++)
{
stResult += UPPER[stLower[i] - 48].ToString() + UNIT[j - i].ToString();
}
}
else
{
stResult = "#E";
}
return stResult;
}
#endregion
}
}
<script type="text/javascript">
function RMB_Convert(n)
{
var strOutput = "";
var strUnit = '仟佰拾亿仟佰拾万仟佰拾元角分';
n += "00";
var intPos = n.indexOf('.');
if (intPos >= 0)
n = n.substring(0, intPos) + n.substr(intPos + 1, 2);
strUnit = strUnit.substr(strUnit.length - n.length);
for (var i=0; i < n.length; i++)
strOutput += '零壹贰叁肆伍陆柒捌玖'.substr(n.substr(i,1),1) + strUnit.substr(i,1);
return strOutput;
}
alert(RMB_Convert(333.3));
</script>
尉迟方
http://www.cnblogs.com/realfun
//根据阿拉伯数字构造汉字数字读法,去年用C写输入法的时候顺便写的,思路:倒着转换(由低位到高位,然后去“零”,然后倒过来
void Num2HZNum(int index, LPTSTR str, LPCTSTR strNum)
{
TCHAR line[MAX_PHRASE_LEN] = _T("");
TCHAR chNums[2][10][2] =
{
{
_T("零"), _T("一"), _T("二"), _T("三"), _T("四")
, _T("五"), _T("六"), _T("七"), _T("八"), _T("九")
},
{
_T("零"), _T("壹"), _T("贰"), _T("叁"), _T("肆")
, _T("伍"), _T("陆"), _T("柒"), _T("捌"), _T("玖")
}
};
TCHAR hz[2][MAX_NUM2ZH_LEN][2] =
{
{
_T(""), _T("十"), _T("百"), _T("千"),
_T("万"), _T("十"), _T("百"), _T("千"),
_T("亿"), _T("十"), _T("百"), _T("千"),
_T("万"), _T("十")
},
{
_T(""), _T("拾"), _T("佰"), _T("仟"),
_T("万"), _T("拾"), _T("佰"), _T("仟"),
_T("亿"), _T("拾"), _T("佰"), _T("仟"),
_T("万"), _T("拾")
}
};
int i;
int pos = 0;
TCHAR temp[MAX_PHRASE_LEN];
for (i=_tcslen(strNum)-1; i>=0; i--)
{
temp[_tcslen(strNum)-1-i] = strNum[i];
}
*line = _T('/0');
for (i=0; i<(int)_tcslen(strNum); i++)
{
if (temp[i] != _T('0') || hz[index][i][0] == _T('万') || hz[index][i][0] == _T('亿'))
_tcscat(line, hz[index][i]);
if (temp[i] == _T('0')
&& (i == 0
|| temp[i-1] == _T('0')
|| line[_tcslen(line) - 1] == _T('万')
|| line[_tcslen(line) - 1] == _T('亿')
)
)
continue;
_tcscat(line, chNums[index][temp[i] - _T('0')]);
}
for (i=0; i<(int)_tcslen(line); i++)
{
str[i] = line[_tcslen(line) - 1 -i];
}
str[i] = _T('/0');
}