js 小写金额转大写

前端之家收集整理的这篇文章主要介绍了js 小写金额转大写前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

<div class="cnblogs_code">

     fraction = ['角','分' digit = ['零','壹','贰','叁','肆','伍','陆','柒','捌','玖' unit ='元','万','亿''','拾','佰','仟' head = n < 0 ? '欠' : ''=        </span><span style="color: #0000ff"&gt;var</span> s = ''<span style="color: #000000"&gt;;

        </span><span style="color: #0000ff"&gt;for</span> (<span style="color: #0000ff"&gt;var</span> i = 0; i < fraction.length; i++<span style="color: #000000"&gt;) {
            s </span>+= (digit[Math.floor(n * 10 * Math.pow(10,i)) % 10] + fraction[i]).replace(/零./,''<span style="color: #000000"&gt;);
        }
        s </span>= s || '整'<span style="color: #000000"&gt;;
        n </span>=<span style="color: #000000"&gt; Math.floor(n);

        </span><span style="color: #0000ff"&gt;for</span> (<span style="color: #0000ff"&gt;var</span> i = 0; i < unit[0].length &amp;&amp; n > 0; i++<span style="color: #000000"&gt;) {
            </span><span style="color: #0000ff"&gt;var</span> p = ''<span style="color: #000000"&gt;;
            </span><span style="color: #0000ff"&gt;for</span> (<span style="color: #0000ff"&gt;var</span> j = 0; j < unit[1].length &amp;&amp; n > 0; j++<span style="color: #000000"&gt;) {
                p </span>= digit[n % 10] + unit[1][j] +<span style="color: #000000"&gt; p;
                n </span>= Math.floor(n / 10<span style="color: #000000"&gt;);
            }
            s </span>= p.replace(/(零.)*零$/,'').replace(/^$/,'零') + unit[0][i] +<span style="color: #000000"&gt; s;
        }
        </span><span style="color: #0000ff"&gt;return</span> head + s.replace(/(零.)*零元/,'元').replace(/(零.)+/g,'零').replace(/^整$/,'零元整'<span style="color: #000000"&gt;);
    }
    console.log(smalltoBIG(</span>99.89)); //玖拾玖元捌角玖分</pre>
原文链接:https://www.f2er.com/js/73980.html

猜你在找的JavaScript相关文章