Math.round - rounds up or down
- 4.4 will be 4, 4.6 will be 5
- if you
Math.round(Math.random() * 10)
you will get numbers from 0 to 10 - total 11 numbers.
Math.floor - rounds DOWN to floor
- 4.4, 4.6, 4.9999 will all be 4
- if you
Math.floor(Math.random() * 10)
you won't get 10. Numbers you get will be between 0 and 9. total 10 numbers.
Math.ceil - rounds UP to ceiling
4.001, 4.4, 4.6 will all be 5
- if you
Math.floor(Math.random() * 10)
you won't get 0. Numbers you get will be between 1 and 10. total 10 numbers.
likewise ceil and floor can be used depending on what you need.
you won't have to do annoying + 1 after the generating a random number, if you know what i mean. - if not just remember what's stated above and you should be good to go.
Tuesday, June 26, 2007
Different rounding methods in ActionScript
Posted by
SONARHYTHM Logic Pro School
at
5:27 PM
Labels: actionscript, actionscript 3.0, flash
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment