|
-
Senior Member
[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.
-
Can you not use the Math.round function or something similiar....
-
Senior Member
Well if I do that it rounds it to either 0 or 1.
-
Ryan Thomson
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
-
Senior Member
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).
-
Bearded (M|G)od
Code:
var num:Number = 0.4431325432;
num = Math.round(num*100)/100;
-
Senior Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|