大写金额转换函数

最近流行大写金额转换函数


今天看到N多人Blog大写金额转换函数,我也来凑个热闹,顺便换个思路
using System;

namespace Excellent.Data
{
    /// <summary> 
    /// 金额类 
    /// </summary> 
    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
        /// <summary> 
        /// 获取大写金额 
        /// </summary> 
        /// <param name="lower">小写金额</param> 
        /// <returns>string</returns> 
        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'); 
}
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值