Click to See Complete Forum and Search --> : Adding in commas
Burrow
02-28-2003, 08:47 PM
Hi,
Is it possible to take a raw number such as
2604506250.00506452
and first off,
add commas to it
2,604,506,250.00506452
and then make that number
2,604,506
and leave off the decimal, and it's corresponding numbers?
Any help is appreciated.
khalidali63
02-28-2003, 08:53 PM
yes you can do it
first
var num = parseInt(2604506250.00506452 )
should get rid of the decimal value
then you have to create a function that can apply commas according to your logic.
Cheers
Khalid
Burrow
02-28-2003, 09:00 PM
ahh,
thank you very much. :)
That'll make my work much easier.
Dan Drillich
02-28-2003, 10:17 PM
Please try -
<script type="text/javascript">
var x = "1234567".split("").reverse().join("");
var n = "";
for (var i=0; i<x.length; i++) {
n += x.charAt(i);
if ((i + 1) % 3 == 0 && i+1 != x.length) {
n += ",";
}
}
n = n.split("").reverse().join("");
alert(n);
// -->
</script>
Burrow
03-01-2003, 11:14 AM
Yes,
that script works also. :)
I would like to thank everyone whom helped me. I appreciate it. So, Thanks!!