转换成大写金额

ExpandedBlockStart.gifContractedBlock.gif/**//*
InBlock.gif===========================================
InBlock.gif//转换成大写金额
InBlock.gif===========================================
ExpandedBlockEnd.gif
*/

None.gifNumber.prototype.toMoney 
= function()
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
InBlock.gif
// Constants:
InBlock.gif
var MAXIMUM_NUMBER = 99999999999.99;
InBlock.gif
// Predefine the radix characters and currency symbols for output:
InBlock.gif
var CN_ZERO= "";
InBlock.gif
var CN_ONE= "";
InBlock.gif
var CN_TWO= "";
InBlock.gif
var CN_THREE= "";
InBlock.gif
var CN_FOUR= "";
InBlock.gif
var CN_FIVE= "";
InBlock.gif
var CN_SIX= "";
InBlock.gif
var CN_SEVEN= "";
InBlock.gif
var CN_EIGHT= "";
InBlock.gif
var CN_NINE= "";
InBlock.gif
var CN_TEN= "";
InBlock.gif
var CN_HUNDRED= "";
InBlock.gif
var CN_THOUSAND = "";
InBlock.gif
var CN_TEN_THOUSAND= "";
InBlock.gif
var CN_HUNDRED_MILLION= "亿";
InBlock.gif
var CN_SYMBOL= "";
InBlock.gif
var CN_DOLLAR= "";
InBlock.gif
var CN_TEN_CENT = "";
InBlock.gif
var CN_CENT= "";
InBlock.gif
var CN_INTEGER= "";
InBlock.gif 
InBlock.gif
// Variables:
InBlock.gif
var integral; // Represent integral part of digit number.
InBlock.gif
var decimal; // Represent decimal part of digit number.
InBlock.gif
var outputCharacters; // The output result.
InBlock.gif
var parts;
InBlock.gif
var digits, radices, bigRadices, decimals;
InBlock.gif
var zeroCount;
InBlock.gif
var i, p, d;
InBlock.gif
var quotient, modulus;
InBlock.gif 
InBlock.gif
if (this > MAXIMUM_NUMBER)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif
return "";
ExpandedSubBlockEnd.gif}

InBlock.gif 
InBlock.gif
// Process the coversion from currency digits to characters:
InBlock.gif//
 Separate integral and decimal parts before processing coversion:
InBlock.gif

InBlock.gif parts 
= (this + "").split(".");
InBlock.gif
if (parts.length > 1
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifintegral 
= parts[0];
InBlock.gifdecimal 
= parts[1];
InBlock.gif
// Cut down redundant decimal digits that are after the second.
InBlock.gif
decimal = decimal.substr(02);
ExpandedSubBlockEnd.gif}

InBlock.gif
else 
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifintegral 
= parts[0];
InBlock.gifdecimal 
= "";
ExpandedSubBlockEnd.gif}

InBlock.gif
// Prepare the characters corresponding to the digits:
InBlock.gif
digits= new Array(CN_ZERO, CN_ONE, CN_TWO, CN_THREE, CN_FOUR, CN_FIVE, CN_SIX, CN_SEVEN, CN_EIGHT, CN_NINE);
InBlock.gifradices
= new Array("", CN_TEN, CN_HUNDRED, CN_THOUSAND);
InBlock.gifbigRadices
= new Array("", CN_TEN_THOUSAND, CN_HUNDRED_MILLION);
InBlock.gifdecimals
= new Array(CN_TEN_CENT, CN_CENT);
InBlock.gif
InBlock.gif 
// Start processing:
InBlock.gif
 outputCharacters = "";
InBlock.gif
// Process integral part if it is larger than 0:
InBlock.gif
if (Number(integral) > 0
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifzeroCount 
= 0;
InBlock.gif
for (i = 0; i < integral.length; i++
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif
= integral.length - i - 1;
InBlock.gif
= integral.substr(i, 1);
InBlock.gifquotient 
= p / 4;
InBlock.gifmodulus 
= p % 4;
InBlock.gif
if (d == "0"
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifzeroCount
++;
ExpandedSubBlockEnd.gif}

InBlock.gif
else 
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif
if (zeroCount > 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifoutputCharacters 
+= digits[0];
ExpandedSubBlockEnd.gif}

InBlock.gifzeroCount 
= 0;
InBlock.gifoutputCharacters 
+= digits[Number(d)] + radices[modulus];
ExpandedSubBlockEnd.gif}

InBlock.gif
InBlock.gif
if (modulus == 0 && zeroCount < 4
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifoutputCharacters 
+= bigRadices[quotient];
ExpandedSubBlockEnd.gif}

ExpandedSubBlockEnd.gif}

InBlock.gif
InBlock.gifoutputCharacters 
+= CN_DOLLAR;
ExpandedSubBlockEnd.gif}

InBlock.gif
InBlock.gif
// Process decimal part if there is:
InBlock.gif
if (decimal != ""
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif
for (i = 0; i < decimal.length; i++
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif
= decimal.substr(i, 1);
InBlock.gif
if (d != "0"
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifoutputCharacters 
+= digits[Number(d)] + decimals[i];
ExpandedSubBlockEnd.gif}

ExpandedSubBlockEnd.gif}

ExpandedSubBlockEnd.gif}

InBlock.gif
InBlock.gif
// Confirm and return the final output string:
InBlock.gif
if (outputCharacters == ""
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifoutputCharacters 
= CN_ZERO + CN_DOLLAR;
ExpandedSubBlockEnd.gif}

InBlock.gif
if (decimal == ""
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifoutputCharacters 
+= CN_INTEGER;
ExpandedSubBlockEnd.gif}

InBlock.gif
InBlock.gifoutputCharacters 
= CN_SYMBOL + outputCharacters;
InBlock.gif
return outputCharacters;
ExpandedBlockEnd.gif}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值