js 金額小寫轉換為大寫

來源:互聯網
上載者:User

標籤:

<script>     jQuery(document).ready(function () {         //當金額文字框失去焦點時,自動將數字轉化為大寫填充到 大寫的文字框中         $("#Amount").blur(function () {             var amount = $("#Amount").val();             amount = AmountLtoU(amount);             $("#CapitalAmount").val(amount);         });     });     function AmountLtoU(num) {         ///<summery>小寫金額轉化大寫金額</summery>         ///<param name=num type=number>金額</param>         if (isNaN(num)) return "";         var strPrefix = "";         if (num < 0) strPrefix = "(負)";         num = Math.abs(num);         if (num >= 1000000000000) return "無效數值!";         var strOutput = "";         var strUnit = ‘仟佰拾億仟佰拾萬仟佰拾元角分‘;         var strCapDgt = ‘零壹貳三肆伍陸柒捌玖‘;         num += "00";         var intPos = num.indexOf(‘.‘);         if (intPos >= 0) {             num = num.substring(0, intPos) + num.substr(intPos + 1, 2);         }         strUnit = strUnit.substr(strUnit.length - num.length);         for (var i = 0; i < num.length; i++) {             strOutput += strCapDgt.substr(num.substr(i, 1), 1) + strUnit.substr(i, 1);         }         return strPrefix + strOutput.replace(/零角零分$/, ‘整‘).replace(/零[仟佰拾]/g, ‘零‘).replace(/零{2,}/g, ‘零‘).replace(/零([億|萬])/g, ‘$1‘).replace(/零+元/, ‘元‘).replace(/億零{0,3}萬/, ‘億‘).replace(/^元/, "零元");     };    </script>

 

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.