JavaScript digital amount to Chinese capital amount

Source: Internet
Author: User

In the Web page sometimes need to convert the amount entered by the user into the capital of the renminbi display, the following methods can be completed automatically complete this function (up to 13-bit integer conversion)

<!DOCTYPE HTML><HTML><Head>    <title>Numbertochinesecapital</title>    <MetaCharSet= "Utf-8"></Head><Body>    <inputtype= "text"ID= "Number"style= "width:200px;">    <spanID= "Chinese"></span></Body><Scripttype= "Text/javascript"src= "Http://cdn.bootcss.com/jquery/1.11.3/jquery.min.js"></Script><Script>    functionnumbertochinesecapital (number) {if (!/^ (0|[ 1-9]\d*) (\.\d+)? $/. Test (number)) {            return 'The number format is incorrect! '; } Number+= 'xx'; varUnit= 'Thousands of Baishi million thousand Baishi thousands of Baishi yuan angle', PointIndex=Number.indexof ('.'), Chinesecapitalstr= "'; //If there are decimals, intercept the integer digits and decimal places        if(PointIndex!== -1) { number=number.substring (0, PointIndex)+Number.substr (PointIndex+ 1, 2); }          //match the corresponding units according to the length of the input amountUnit=Unit.substr (Unit.length-number.length);  for (varI= 0; I<number.length; I++) {Chinesecapitalstr+= '0 One and three Woolu Qi Ba Jiu'. CharAt (Number.charat (i))+Unit.charat (i); }          returnchinesecapitalstr. Replace (/0 (Thousand | hundred | ten | corner)/G,'0'). Replace (/(0) +/G,'0'). Replace (/0 (million | billion | yuan)/G,' $'). Replace (/(million) million | Yuan (pick)/G,'$1$2'). Replace (/^ $0? | 0 min/G,"'). Replace (/thousand/G,'Qian'). Replace (/Hundred/G,'Bai'). Replace (/10/G,'Pick'). Replace (/$ $/G,'meta-integer'); }      $('#number'). KeyUp (function() {        $('#chinese'). Text (Numbertochinesecapital ($ ( This). Val ())); });</Script></HTML>

JavaScript digital amount to Chinese capital amount

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.