Currency formatting
Example
1 <!DOCTYPE HTML>2 <HTML>3 <Head>4 <Scriptsrc= "Http://code.jquery.com/jquery-migrate-1.2.1.min.js"></Script>5 </Head>6 <Body>7Hello<BR>8 <Script>9 //format money:x,xxx.xxTen functionMoneyformat (money, digit) { One Digit=Digit> 0 &&Digit<= - ?Digit:2; A Money=parsefloat (Money). toFixed (digit); - varIntegerarr=Money.split (".")[0].split (""). reverse (); - varDecimals=Money.split (".")[1]; the Temparr= ""; - for (varI=0, K=Integerarr.length;i<K;i++) { - varCammatag=(i+1)%3==0 &&(i+1)!=K.length? "," : ""; - Temparr+=Integerarr[i]+Cammatag; + } - Money=Temparr.split (""). Reverse (). Join ("") + "." +decimals; + returnMoney ; A } at document.write (Moneyformat (11111.111,-2)+"<br>"); - document.write (Moneyformat (22222.222,5)+"<br>"); - document.write (Moneyformat (3333333.333,1)+"<br>"); - </Script> - </Body> - </HTML>
Result
JavaScript currency formatting