Eternity Angel
10-05-2002, 08:37 PM
Howdy, it's my inquisitive self again.
I am curious as to if JavaScript has a specific command to split a number like 1267618, and add commas where needed, so it would make 1,267,618?
If there ISN'T, then do you have a script that could do it? I don't think my way is that effective, since it's so bulky...
var random = 66298762343;
var random2 = "";
var random3 = String(random);
var temp = 0;
for (b=random3.length;b>=0;b--) {
if (temp >= 3) {
temp=0;
random2 = ","+random3.charAt(b)+random2;
} else {
random2 = random3.charAt(b)+random2;
}
temp++;
}
if (random2.charAt(0) == ",") {
random3 = "";
for (a=1;a<random2.length;a++) {
random3 = random3+random2.charAt(a);
}
random2 = random3;
}
alert(random2);
See? It doesn't look too good for just adding it to ONE number. Any help is greatly appreciated, since this has been annoying me for awhile (just the bulkiness of it).
I am curious as to if JavaScript has a specific command to split a number like 1267618, and add commas where needed, so it would make 1,267,618?
If there ISN'T, then do you have a script that could do it? I don't think my way is that effective, since it's so bulky...
var random = 66298762343;
var random2 = "";
var random3 = String(random);
var temp = 0;
for (b=random3.length;b>=0;b--) {
if (temp >= 3) {
temp=0;
random2 = ","+random3.charAt(b)+random2;
} else {
random2 = random3.charAt(b)+random2;
}
temp++;
}
if (random2.charAt(0) == ",") {
random3 = "";
for (a=1;a<random2.length;a++) {
random3 = random3+random2.charAt(a);
}
random2 = random3;
}
alert(random2);
See? It doesn't look too good for just adding it to ONE number. Any help is greatly appreciated, since this has been annoying me for awhile (just the bulkiness of it).