Divide by 1000, and use
.toFixed(3)
to fix the number of decimal places.var output = (input/1000).toFixed(3);
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
No comments:
Post a Comment