Home > Web Front-end > JS Tutorial > A simple example of converting JS numbers to uppercase amounts

A simple example of converting JS numbers to uppercase amounts

高洛峰
Release: 2017-01-09 14:54:09
Original
1426 people have browsed it

JS 数字转换为大写金额的简单实例

function DX(n) {
 
    if (!/^(0|[1-9]\d*)(\.\d+)?$/.test(n))
      return "数据非法";
    var unit = "千百拾亿千百拾万千百拾元角分", str = "";
      n += "00";
    var p = n.indexOf('.');
    if (p >= 0)
      n = n.substring(0, p) + n.substr(p+1, 2);
      unit = unit.substr(unit.length - n.length);
    for (var i=0; i < n.length; i++)
      str += &#39;零壹贰叁肆伍陆柒捌玖&#39;.charAt(n.charAt(i)) + unit.charAt(i);
    return str.replace(/零(千|百|拾|角)/g, "零").replace(/(零)+/g, "零").replace(/零(万|亿|元)/g, "$1").replace(/(亿)万|壹(拾)/g, "$1$2").replace(/^元零?|零分/g, "").replace(/元$/g, "元整");
}
Copy after login

   

以上这篇JS 数字转换为大写金额的简单实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持PHP中文网。

更多JS 数字转换为大写金额的简单实例相关文章请关注PHP中文网!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template