Copy the code code as follows:
//Amount format conversion
function parsePrice(s) {
var n = 2 //Set the number of decimal places to retain
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 '¥' + t.split("").reverse().join("") + "." + r;
}
use:
Copy the code code as follows:
var m=10;
parsePrice(m);//Output: ¥10.00
var m=12.2
parsePrice(m);//Output: ¥12.20
var m=12.31
parsePrice(m);//Output: ¥12.31
Additional information: Re-open a tab in the browser based on the URL settings:
Copy the code code as follows:
window.open("http://www.allinpay.com");