Alex Piotto
09-27-2002, 04:26 PM
Hi everybody!
I am using this code to round a number to two decimal after the dot
<SCRIPT>
function round(number,X) {
// rounds number to X decimal places, defaults to 2
X = (!X ? 2 : X);
return Math.round(number*Math.pow(10,X))/Math.pow(10,X);
}
</SCRIPT>
So, for example, a number like this 123456789.65786578657
will be 123456789.66
Now, I need to put inside this script also a function to add the commas in the thousands places, without losing the rounded decimals.
I tryed several scripts around, but, or I lose the decimals or a comma is added in front of the dot... :(
finally, I need my number to be 123,456,789.66 !
Any help?
Thanks
Alex
I am using this code to round a number to two decimal after the dot
<SCRIPT>
function round(number,X) {
// rounds number to X decimal places, defaults to 2
X = (!X ? 2 : X);
return Math.round(number*Math.pow(10,X))/Math.pow(10,X);
}
</SCRIPT>
So, for example, a number like this 123456789.65786578657
will be 123456789.66
Now, I need to put inside this script also a function to add the commas in the thousands places, without losing the rounded decimals.
I tryed several scripts around, but, or I lose the decimals or a comma is added in front of the dot... :(
finally, I need my number to be 123,456,789.66 !
Any help?
Thanks
Alex