如何像jquery中的数字格式一样简单地格式化


How to format like number format in jquery on the simple way?

我想在php中从ajax替换hrg1+id上的内容,如下所示:

<p id="hrg1<?php echo $id; ?>">Rp.<?php echo number_format($price,0,",",".") ?></p>

但是ajax传递的值是这样的:

$("#hrg1"+id).html("Rp."+price);

如何像jquery中的数字格式一样简单地格式化?

Rp.<?php echo number_format($price,0,",",".") ?>

感谢提前

这里是我笔记上的参考:

function akoma(nStr){
nStr += '';
x = nStr.split(',');
x1 = x[0];
x2 = x.length > 1 ? ',' + x[1] : '';
var rgx = /('d+)('d{3})/;
while (rgx.test(x1)) {
    x1 = x1.replace(rgx, '$1' + '.' + '$2');
}
return x1 + x2;
}
alert(akoma(price));
$("#price"+id).html(akoma(price(0)));