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