A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: [RESOLVED] How to show only two digits after dot?

  1. #1
    Senior Member Shnitzel's Avatar
    Join Date
    May 2007
    Location
    IL
    Posts
    130

    resolved [RESOLVED] How to show only two digits after dot?

    Hi,
    I have function returning me a number between 0 and 1. The code works fine but I want to show the number in a dynamic text box.
    The problem is that it shows the full number like so: 0.12975439
    I want to show only 2 digits after the dot, like so: 0.12

    How can I do that?
    Thanks in advance.

  2. #2
    Senior Member
    Join Date
    Sep 2007
    Location
    UK
    Posts
    194
    Can you not use the Math.round function or something similiar....

  3. #3
    Senior Member Shnitzel's Avatar
    Join Date
    May 2007
    Location
    IL
    Posts
    130
    Well if I do that it rounds it to either 0 or 1.

  4. #4
    Ryan Thomson EvolveDesigns's Avatar
    Join Date
    Oct 2001
    Location
    British Columbia
    Posts
    3,338
    hmm.. i think you might have to write a fancy function to do this, there's no prebuilt method.. the closest thing i can think of is maxChars, but I believe that only works if the user tries to type in a textfield, dynamic code driven content would override this...

    how are you creating your random number? When I try it I always get a round number:
    trace(random(3));//outputs 0,1 or 2
    Evolve Designs Interactive Media
    the natural selection

  5. #5
    Senior Member Shnitzel's Avatar
    Join Date
    May 2007
    Location
    IL
    Posts
    130
    I'm not exactly searching for a random number. I kind of get numeric values of all sorts of stuff from files loaded to file (Like photos - I get their size in bytes then I turned it to megabytes).

  6. #6
    Bearded (M|G)od MyFriendIsATaco's Avatar
    Join Date
    Dec 2002
    Location
    Awesomeville.
    Posts
    3,045
    Code:
    var num:Number = 0.4431325432;
    num = Math.round(num*100)/100;

  7. #7
    Senior Member Shnitzel's Avatar
    Join Date
    May 2007
    Location
    IL
    Posts
    130
    Thank you very much, it worked

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