A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Dynamic text numbers, add comma

  1. #1
    Senior Member
    Join Date
    Oct 2000
    Posts
    123

    Dynamic text numbers, add comma

    Need to add commas for formatting numbers to a dynamic text field. For example, 11000 should read 11,000.

    Anyone have a quick script that would take care of this?

    thanks

  2. #2
    Senior Member
    Join Date
    Oct 2000
    Posts
    123
    Well, after some trial and error I got it to work.

    This won't work for numbers greater than xxx,xxx but works in this case.


    textnumber = 1242;
    textnumber = textnumber.toString();
    textnumber = (textnumber.slice(-5,-3))+","+(textnumber.slice(-3));

  3. #3
    Junior Member
    Join Date
    Sep 2008
    Posts
    1
    var money = 999999999;
    money = money.toString();
    money = (money.slice(-9,-6))+","+(money.slice(-6,-3))+","+(money.slice(-3));

    This works all u have to do is keep adding on to the code, say you want to go into the billions, you would need to add " (money.slice(-12,-9))+","+ " in front of the equal sign.

    So if your variable was 100239100293 it would show up 100,239,100,293 instead of 100239,100,293 with the previous code.

  4. #4
    Member
    Join Date
    Apr 2007
    Posts
    56
    I tried this and when I run a trace on value for my dynamic field I see the comma but I get NaN in my Dynamic Text Display

  5. #5
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    huh?

    what is 'value'?

    what is your code? you havent given us anything to work with?

    var money = 999999999;
    money = money.toString();
    money = (money.slice(-9,-6))+","+(money.slice(-6,-3))+","+(money.slice(-3));
    trace("MONEY: "+money);

    someTextField_txt.text = money;

    seems to work fine for 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