 # Thread: Round function ...how to?

1. ## Round function ...how to?

Hi guys!

I'm trying to calculate damage that will be divided between health and shield of the player. This damage always has to be a round integer, because the counters will mess up decimals.

However, if I use the round(damage/2) value, it still divides odd numbers into decimals.

Please help me on this one. Also, is there somewhere a help page that shows all different stuff of how to handle integers with all those abs() and rounds() and whatnot?

Thanks a lot   Reply With Quote

2. ## Re: Round function ...how to?

there are a few equations;

int(10. = 10
floor(10. = 10
ceil(10. = {10 for x = 0, 11 for x > 0}
round (10. = {10 for X < 5, 11 for X >= 5}

if the rounding function isn't making your counter a decimal, its probably a different problem, however. Make sure to try "int()", first. But also- when a counter is given a decimal number, it will use that decimal and stay a decimal counter even if you feed it only integers later. So you need to configure it in the level editor to not do decimals. You can probably do that with "number of digits after the decimal set to 0"

but uh, just make sure that you're not feeding floats into your counter in some other event in your program. As long as everything only gives it integers, it should stay an integer.  Reply With Quote

3. ## Re: Round function ...how to?

Just to clarify:

Int() rounds positive numbers down, and rounds negative numbers up.

Floor() always rounds numbers down.

Ceil() always rounds numbers up.

Round() rounds numbers to the nearest whole number (ie. up if the fraction is >=.5 or down if the fraction is <.5)

Abs() just makes a value positive - a float will remain a float.  Reply With Quote

4. ## Re: Round function ...how to?

oh yeah, negatives, my bad :p  Reply With Quote

5. ## Re: Round function ...how to?

Just a quick thank you I had another multiplier in the damage calculation process which changed it into a floating number I guess. Thanks for explaining all this, it is very helpful   Reply With Quote

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•