JS格式化金额
JS格式化金额成¥123,123.00
/**
* 价格显示,用,隔开
* @param value 分
* @returns {string}
*/
function showPrice(value) {
if (!value) return '¥0.00';
var ab = "";
var c = String(value);
if (c.indexOf('.') > 0) {
c = c.split('.')[0];
}
var d = 0;
for(var i = c.length - 1; i >= 0; i--) {
if (d == 3) {
ab = ',' + ab;
d = 0;
}
ab = c[i] + ab;
d++;
}
if (String(value).indexOf('.') > 0) {
var c = String(value).split('.')[1];
if (c.length < 2) {
c = c + "0";
}
return "¥" + ab + "." + c;
} else {
return "¥" + ab + ".00";
}
}