How to add commas (100000 to 100,000)
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: How to add commas (100000 to 100,000)

  1. #1
    Junior Member
    Join Date
    Jun 2010
    Posts
    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. #2
    Senior Member
    Join Date
    Aug 2006
    Posts
    322

    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. #3
    Senior Member
    Join Date
    Aug 2006
    Posts
    322

    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
    Last edited by marlopax; 07-01-2010 at 12:35 PM.

  4. #4
    Junior Member
    Join Date
    Mar 2014
    Posts
    1

    adding a comma

    Quote Originally Posted by marlopax View Post
    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
  •  




Click Here to Expand Forum to Full Width


HTML5 Development Center

Poll by Flashkit.com