USERNAME:
PASSWORD:
Save Info!
Logging in…
This topic is 1 page long.
[ Profile | Posts | Contact ]
Posted at: 10/4/09 04:38 AM
Sign-Up: 04/12/09
Posts: 219
I have a game where money is used, but I divide other variables to find out how much an item is worth. So naturally I used Math.floor to round it to a whole number. But that's not helpful when you want to deal with penies (just not 10th's of a penny and etc). Is there anyway to round to 2 decimal places?
some people get them, some people don't;
Posted at: 10/4/09 04:49 AM
Sign-Up: 08/10/05
Posts: 6,027
Math.round(x * 100) / 100
By multiplying by 100 you're only rounding the digits past the 2nd decimal place. Then by dividing by 100 you're putting the decimal place back in the right position.
Portfolio(Under construction): UnknownFury.com | Msn: giant_ak_47@msn.com | Contact: me@unknownfury.com Follow me on twitter!
Posted at: 10/4/09 04:56 AM
At 10/4/09 04:49 AM, UnknownFury wrote: Math.round(x * 100) / 100 By multiplying by 100 you're only rounding the digits past the 2nd decimal place. Then by dividing by 100 you're putting the decimal place back in the right position.
worked perfectly! thanks alot
All times are Eastern Standard Time (GMT -5) | Current Time: 06:43 AM
<< Back