A Flash Developer Resource Site

1. ## How to add commas (100000 to 100,000)

Hi,
1st thread here. Trying to build a calculator with this code and it works so far.
----------------------------------------------------------------------
stop();
/* SET VARIABLES */
var r1c1:Number = 10;
var r2c1:Number = 1000;
var r3c1:Number = 50;
var r4c1:Number = 500;
var r5c1:Number = 2;
var r6c1:Number = 500;
var r7c1:Number = 30;
var r8c1:Number = 1000;

var r1c2:Number = 50;
var r2c2:Number = 200;
var r3c2:Number = 500;
var r4c2:Number = 1000;
var r5c2:Number = 10;
var r6c2:Number = 10;
var r7c2:Number = 30000;
var r8c2:Number = 100;

// Do I still need this bit of code if everything works???
//var r1total:Number = ((r1c1*r1c2)/60)*60000;
//var r2total:Number = r2c1 * r2c2;
//var total:Number = r1total + r2total;

/* CALCULATE CHANGING VALUES */
onEnterFrame = function () {

r1total = ((Number(r1c1) * Number(r1c2))/60) * 60000 + ".00";
r2total = Number(r2c1) * Number(r2c2) + ".00";
r3total = Number(r3c1) * Number(r3c2) + ".00";
r4total = Number(r4c1) * Number(r4c2) + ".00";
r5total = Number(r5c1) * Number(r5c2) * 35000 + ".00";
r6total = Number(r6c1) * Number(r6c2) * 25 + ".00";
r7total = Number(r7c1) * Number(r7c2) + ".00";
r8total = Number(r8c1) * Number(r8c2) + ".00";

// TOTAL
total = " \$" + (Number(r1total) + Number(r2total) + Number(r3total) + Number(r4total) + Number(r5total) + Number(r6total) + Number(r7total) + Number(r8total)) + ".00" ;
}

----------------------------------------------

But how do I add the comma to make numbers format to 100000 to 100,000 to 1,000,000? I've checked out other threads, but its still not working.

Any help would be very much appreciated. Thanks!!!!!!

2. ## Commas

Code:
```var n = "";
var num = 1234567890;
if (length(num)>3) {
for (var i = 0; i<length(num); i++) {
if (length(num)>3) {
sub = substring(num, length(num)-2, 3);
num = substring(num, 0, length(num)-length(sub));
n = ","+sub+n;
v = num+n+".00";
}
}
} else {
v = num+".00";
}
trace(v);```
Think you are looking similar to this....

MarlöPax

3. ## Commas from function

Code:
```stop();
/* SET VARIABLES */
var r1c1:Number = 10;
var r2c1:Number = 1000;
var r3c1:Number = 50;
var r4c1:Number = 500;
var r5c1:Number = 2;
var r6c1:Number = 500;
var r7c1:Number = 30;
var r8c1:Number = 1000;

var r1c2:Number = 50;
var r2c2:Number = 200;
var r3c2:Number = 500;
var r4c2:Number = 1000;
var r5c2:Number = 10;
var r6c2:Number = 10;
var r7c2:Number = 30000;
var r8c2:Number = 100;

// Do I still need this bit of code if everything works???
//var r1total:Number = ((r1c1*r1c2)/60)*60000;
//var r2total:Number = r2c1 * r2c2;
//var total:Number = r1total + r2total;

/* CALCULATE CHANGING VALUES */
function currencyFormat() {

r1total = ((Number(r1c1)*Number(r1c2))/60)*60000;
r2total = Number(r2c1)*Number(r2c2);
r3total = Number(r3c1)*Number(r3c2);
r4total = Number(r4c1)*Number(r4c2);
r5total = Number(r5c1)*Number(r5c2)*35000;
r6total = Number(r6c1)*Number(r6c2)*25;
r7total = Number(r7c1)*Number(r7c2);
r8total = Number(r8c1)*Number(r8c2);

// TOTAL
num = (Number(r1total)+Number(r2total)+Number(r3total)+Number(r4total)+Number(r5total)+Number(r6total)+Number(r7total)+Number(r8total));
}
currencyFormat();
var n = "";
//var num = 1234567890;
if (length(num)>3) {
for (var i = 0; i<length(num); i++) {
if (length(num)>3) {
sub = substring(num, length(num)-2, 3);
num = substring(num, 0, length(num)-length(sub));
n = ","+sub+n;
v = "\$"+num+n+".00";
}
}
} else {
v = "\$"+num+".00";
}
total.text = v;

trace(v);```

Think this will help, but what type of calculator you are trying to built?

Details will help more to understand.

MarlöPax

Originally Posted by marlopax
Code:
```var n = "";
var num = 1234567890;
if (length(num)>3) {
for (var i = 0; i<length(num); i++) {
if (length(num)>3) {
sub = substring(num, length(num)-2, 3);
num = substring(num, 0, length(num)-length(sub));
n = ","+sub+n;
v = num+n+".00";
}
}
} else {
v = num+".00";
}
trace(v);```
Think you are looking similar to this....

MarlöPax

I have a code for calculator function to calculate the house loan,
but i want the comma appear automatically when we insert the number, can u help me

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

 » Home » Movies » Tutorials » Submissions » Board » Links » Reviews » Feedback » Gallery » Fonts » The Lounge » Sound Loops » Sound FX » About FK » Sitemap