Javascript sets the amount style conversion to keep the two digit decimal sample code



//Conversion of amount format
function parsePrice(s) {
var n = 2 //Sets the number of decimal places to be reserved
s = parseFloat((s + "").replace(/[^d.-]/g, "")).toFixed(n) + "";
var l = s.split(".")[0].split("").reverse();
var r = s.split(".")[1];
var t = "";
for (i = 0; i < l.length; i++) {
t += l[i];
}
return ' RMB ' + t.split("").reverse().join("") + "." + r;
}

Use:


var m=10;
parsePrice(m);//Output:  RMB 10.00

var m=12.2
parsePrice(m);//Output:  RMB 12.20

var m=12.31
parsePrice(m);//Output:  RMB 12.31

Additional information: set in the browser according to the URL, reopen a TAB:


window.open("http://www.allinpay.com");