Encapsulate JS thousand bits plus commas and delete commas

Source: Internet
Author: User

                //encapsulate JS thousand bits plus commas and delete commasAlert (Format (2545678754.020001))//2,545,678,754.03Alert (Format (-2545678754.020001))//-2,545,678,754.02Alert (Format (2545678754.000000000009));//when the value is long, there will be a problem with the number being intercepted.Alert (Delformat (' 2,545,678,754.03 '));//2545678754.03Alert (Delformat (' -2,545,678,754.03 '));//-2545678754.03                                functionformat (num) {varSnum=num.tofixed (2) + ",//leave the incoming value "rounded" for 2 decimal placesre=/(\d+) (\d{3})/; if(/\.\d{3}/.test (num+ ") ){                        if(Snum.charat (0)! = '-'){                            //if the value passed in is not more than two decimal places, move forward 1 to reserve 2 decimal places, such as: 1.2400001-1.25Snum=snum.substring (0,snum.length-1) + (parseint (Snum.slice (-1)) +1); }                    }    //There are too many things to do in the 1, such as 0.999-0.0009                                             while(Re.test (snum)) {Snum=snum.replace (Re, ' $1,$2 ')); }                                        returnSnum; }                                functionDelformat (snum) {returnSnum.replace (/,/g, "); }

Encapsulate JS thousand bits plus commas and delete commas

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.