JS 人民幣大寫

來源:互聯網
上載者:User

標籤:io   ar   java   for   sp   on   2014   cti   bs   

/***
** HongShijin
** [email protected]
** 2014-10-15 9:13:00.00000
** text/javascript
***/

 

(function ($)
{

Number.prototype.toRmbString = function ()
{
var c =
{
n: [38646, 22777, 36144, 21441, 32902, 20237, 38470, 26578, 25420, 29590, 25972, 36000], // "零壹貳三肆伍陸柒捌玖整負";
u: [20191, 20336, 25342, 20140, 20191, 20336, 25342, 21513, 20191, 20336, 25342, 20806, 20191, 20336, 25342, 20740, 20191, 20336, 25342, 33836, 20191, 20336, 25342, 22278, 35282, 20998, 21400, 27627], // "仟佰拾京仟佰拾吉仟佰拾兆仟佰拾億仟佰拾萬仟佰拾圓角分厘毫";//"仟佰拾京仟佰拾吉仟佰拾兆仟佰拾億仟佰拾萬仟佰拾圓角分厘毫"
m: this
};
if (c.m < 0)
c.m *= -1;
for (var i = c.n.length - 1; i >= 0; i--)
{
c.t = c.n[i];
c[c.t] = String.fromCharCode(c.t);
c.n[i] = c[c.t];
}
for (var i = c.u.length - 1; i >= 0; i--)
{
c.t = c.u[i];
c[c.t] = String.fromCharCode(c.t);
c.u[i] = c[c.t];
}
c.t = c.m.toFixed(4).replace(‘.‘, ‘‘).replace(/^0+([0-9])/img, ‘$1‘);
if (c.t == "0")
return c[38646] + c[22278] + c[25972]; // "零圓整";

if (c.t.length > c.u.length)
throw { message: ‘the input value too max.‘ };

c.u = c.u.splice(c.u.length - c.t.length, c.t.length);
for (var i = c.t.length - 1; i >= 0; i--)
c.t = c.t.substring(0, i) + c.n[String.charCodeAt(c.t.substring(i, i + 1)) - String.charCodeAt(‘0‘)] + c.u[i] + c.t.substring(i + 1, c.t.length);
c.m = new RegExp(c[38646] + ‘+[^‘ + c[22278] + c[33836] + c[20740] + c[20806] + c[21513] + c[20140] + ‘]‘, ‘img‘);
c.t = c.t.replace(c.m, c[38646]); // /零+[^圓萬億兆吉京]/img, ‘零‘ //t = "壹仟零佰零拾零京三仟零佰伍拾貳吉零仟零佰零拾零兆三仟伍佰貳拾零億肆仟零佰貳拾零萬零仟零佰零拾伍圓壹角零分零厘伍毫";
c.m = new RegExp(c[38646] + ‘{2,}‘, ‘img‘);
c.t = c.t.replace(c.m, c[38646]); // /零{2,}/img, ‘零‘ //t = "壹仟零零零京三仟零伍拾貳吉零零零零兆三仟伍佰貳拾零億肆仟零貳拾零萬零零零伍圓壹角零零伍毫"
c.m = new RegExp(c[38646] + ‘+([‘ + c[22278] + c[33836] + c[20740] + c[20806] + c[21513] + c[20140] + ‘])‘, ‘img‘);
c.t = c.t.replace(c.m, ‘$1‘); // /零+([圓萬億兆吉京])/img, ‘‘ //t = "壹仟零京三仟零伍拾貳吉零兆三仟伍佰貳拾零億肆仟零貳拾零萬零伍圓壹角零伍毫"
c.m = new RegExp(‘([‘ + c[33836] + c[20740] + c[20806] + c[21513] + c[20140] + ‘])[‘ + c[33836] + c[20740] + c[20806] + c[21513] + c[20140] + ‘]+‘, ‘img‘);
c.t = c.t.replace(c.m, ‘$1‘); // /([萬億兆吉京])[萬億兆吉京]+/img, ‘$1‘ //t = "壹仟京三仟零伍拾貳吉兆三仟伍佰貳拾億肆仟零貳拾萬零伍圓壹角零伍毫"
c.m = new RegExp(‘^[‘ + c[33836] + c[20740] + c[20806] + c[21513] + c[20140] + ‘]+‘, ‘img‘);
c.t = c.t.replace(c.m, ‘‘); // /^[萬億兆吉京]+/img, ‘‘ //"壹仟京三仟零伍拾貳吉三仟伍佰貳拾億肆仟零貳拾萬零伍圓壹角零伍毫"
if (c.t.substring(0, 1) == c[38646])// 零
c.t = c.t.substring(1, c.t.length);
if (c.t.substring(c.t.length - 1, c.t.length) == c[38646])// 零
c.t = c.t.substring(0, c.t.length - 1);
if (c.t.substring(c.t.length - 1, c.t.length) == c[22278])// 圓
c.t = c.t + c[25972]; // "整"
if (this >= 0)
return c.t;

return c[36000] + c.t; // 負 負
};

Number.prototype.toRmb = function ()
{
return this.toRmbString();
};

Number.prototype.rmb = function ()
{
return this.toRmbString();
};

})(null);

//將數字轉換為會計可用的人民幣大寫格式。

JS 人民幣大寫

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.