I have number like this in my html
<div class=number>950000</div>
and I want jQuery change it to
<div class=number>Rp. 950.000</div>
How can I do that in jQUery?
I have number like this in my html
<div class=number>950000</div>
and I want jQuery change it to
<div class=number>Rp. 950.000</div>
How can I do that in jQUery?
Divide by 1000, and use .toFixed(3)
to fix the number of decimal places.
var output = (input/1000).toFixed(3);
[EDIT]
The above solution only applies if the dot in the original question is for a decimal point. However the OP's comment below implies that it is intended as a thousands separator.
In this case, there isn't a single line solution (Javascript doesn't have it built in), but it can be achieved with a fairly short function.
A good example can be found here: http://www.mredkj.com/javascript/numberFormat.html#addcommas
Alternatively, a more complex string formatting function which mimics the printf()
function from the C language can be found here: http://www.diveintojavascript.com/projects/javascript-sprintf