JS Standardized Price

Source: Internet
Author: User

Normalized Total price s: Total Price, N: Keep several decimals

function Fmoney (s, N) {

n = n > 0 && n <= 20? N:2;

s = parsefloat ((s + ""). Replace (/[^\d\.-]/g, "")). ToFixed (n) + "";//change the number of n here can also determine the number of decimal digits to keep

var L = s.split (".") [0].split (""). Reverse (),

r = S.split (".") [1];

t = "";

for (i = 0; i < l.length; i++) {

T + = L[i] + ((i + 1)% 3 = = 0 && (i + 1)! = L.length? "," : "");

}

Return T.split (""). Reverse (). Join ("") + "." + r.substring (0, 2);//reserve 2 decimal places if you want to change the substring the last number of changes can be

}

JS Standardized Price

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.