Forum Topic: Round to 2 decimal places? AS2

(57 views • 2 replies)

This topic is 1 page long.

<< < > >>
Crying

Apple-Juice

Reply To Post Reply & Quote

Posted at: 10/4/09 04:38 AM

Apple-Juice LIGHT LEVEL 02

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;

BBS Signature

None

UnknownFury

Reply To Post Reply & Quote

Posted at: 10/4/09 04:49 AM

UnknownFury EVIL LEVEL 26

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!


None

Apple-Juice

Reply To Post Reply & Quote

Posted at: 10/4/09 04:56 AM

Apple-Juice LIGHT LEVEL 02

Sign-Up: 04/12/09

Posts: 219

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

some people get them, some people don't;

BBS Signature

All times are Eastern Standard Time (GMT -5) | Current Time: 06:43 AM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!