# [Poll] Rounding Up/Down?

## What is your preferred method of rounding?

• ### Math.floor()

• Total voters
6

#### Frostorm

##### []D[][]V[][]D aka "Staf00" Just a quick survey. Do you guys typically round up (`Math.ceil()`), round down (`Math.floor()`), or round to the nearest integer (`Math.round()`)? Or perhaps you use different methods in various situations. If so, when do you round up? When do you round down? Etc...

#### ATT_Turan

##### Forewarner of the Black Wind The counter-question is how often would it make any difference? I most often truncate any decimals (which is rounding down, but not because I care about rounding down - it's just the fastest operation).

• Frostorm

#### Frostorm

##### []D[][]V[][]D aka "Staf00" At the end of the day, you still have to pick one right? Why is rounding down faster than the others? Does it take less processing power or something (not that it would be noticeable)? Wouldn't rounding up be just as fast as rounding down?

Or if you're using small numbers, rounding can be a noticeable difference. For example, I had my units' movement range based on a function of the character's Speed stat, and movement range typically only ranges from 1-5 tiles or so. So rounding up or down can be a difference of up to 20%!

#### Nolonar

##### Veteran Just a quick survey. Do you guys typically round up (`Math.ceil()`), round down (`Math.floor()`), or round to the nearest integer (`Math.round()`)? Or perhaps you use different methods in various situations. If so, when do you round up? When do you round down? Etc...
Depends on what I'm trying to do.

If I need integer operations (e.g. `5 / 2 = 2`), I use `Math.floor()`. If I need to display floating numbers, but don't want the number to have a bazillion decimal digits, I may use `Math.round()` instead.

They each have their use-case, though I don't remember when I ever needed `Math.ceil()`.

Why is rounding down faster than the others? Does it take less processing power or something (not that it would be noticeable)? Wouldn't rounding up be just as fast as rounding down?
Because of how modern computers handle fractional numbers (aka "float" and "double").

Floats (and doubles) are constructed as: `2^x * 1.f` (`x` being the exponent, and `f` being the fraction). This may look complicated, but simply put: one part represents the number, e.g. 12345, and the other part represents the position of the decimal point, e.g. 2. So using my example, `0.12345 * 10^2 = 12.345`. Obviously, the computer will use binary numbers instead (and instead of `0.`, it will use `1.`), but the basic principle is identical and just as simple.

This means that if you're trying to convert a number from fractional to integral, you simply take the first `x` digits of `f` (if `x` is positive) and add 1 to the left end of the number. If `x` is 0, the number is 1, and if `x` is negative, the number is 0.

If you wanted to round up, you'd need to additionally look at the digits you don't take, and see if at least one of them is non-zero (and add 1 to the number if needed). This extra work is why rounding up is slower than rounding down.

• Frostorm and ATT_Turan

#### kirbwarrior

##### Veteran I prefer to not round if I can help it. But when I have to, I often try to round in the player's favor. Otherwise, I drop fractions (round towards 0) but only at the end of the equation (namely, when the number actually matters, such as the end result of damage).

• Frostorm

#### ATT_Turan

##### Forewarner of the Black Wind At the end of the day, you still have to pick one right? Why is rounding down faster than the others? Does it take less processing power or something (not that it would be noticeable)? Wouldn't rounding up be just as fast as rounding down?
In addition to what Nolonar explained, I typically work with languages other than JavaScript, that use data types or classes. So putting a value into an integer class immediately discards the decimal points, which is faster than running the value through a function that modifies it either way.
Or if you're using small numbers, rounding can be a noticeable difference. For example, I had my units' movement range based on a function of the character's Speed stat, and movement range typically only ranges from 1-5 tiles or so. So rounding up or down can be a difference of up to 20%!
You're right about how much of a difference that is. My experience with board/role-playing game rules puts me in the mindset of thresholds - that is, for example, every 6 points of Speed gives a square of movement, so I'd be using that and not ending up with decimals in the first place. But you should do it whichever way you find better for your game's experience.

• Frostorm and kirbwarrior

#### kirbwarrior

##### Veteran My experience with board/role-playing game rules
I just realized I answered with this in mind instead of programming XD But my answer still applies. As you said, let the system automatically truncate for you.

• Frostorm and ATT_Turan

#### Frostorm

##### []D[][]V[][]D aka "Staf00" @Nolonar Oh cool, I learned something new and interesting today, thx!
for example, every 6 points of Speed gives a square of movement
Hmm, I thought of doing it like that as well. Which would be functionally equivalent to rounding down, right? Like `moveRange = Math.floor(a.agi / 6)`

Anyways, I brought the subject up because I was going thru Yanfly's sample project and noticed that sometimes things were rounded up and other times rounded down. I just wanted to figure out the reasoning for doing things that way.

#### ATT_Turan

##### Forewarner of the Black Wind Hmm, I thought of doing it like that as well. Which would be functionally equivalent to rounding down, right?
Functionally, yes, which is what I indicated in my first reply. Although Math.trunc() is more accurate for this usage than Math.floor().
Anyways, I brought the subject up because I was going thru Yanfly's sample project and noticed that sometimes things were rounded up and other times rounded down. I just wanted to figure out the reasoning for doing things that way.
If you're asking in reference to a specific example, and you can't figure it out from reading through the code, then the question would be more usefully asked about that example rather than generally (less "What do you do" and more "Why did Yanfly do this"). That will get you more specifically useful answers.

What spots in this sample project are you curious about?

#### TheoAllen

##### Self-proclaimed jack of all trades For stats, it is rounding down.
For damage done, it is the nearest integer.

The stats are shown in the battle user interface as well as the damage formula.
So, if I use `a.atk * modifier`, if the attack stat is supposed to be 90.9, it becomes 90. The reason is that the modifier could be massive depends on the buff you have before attacking (or enemy debuff). One integer difference could mean several numbers up. However, rounding up or down to the damage number virtually doesn't make a difference at all.

There is an exception to this.
If you're dealing 8x damage, and your damage is supposed to be 15.6 each hit, then it means you deliver +8 more damage.

### Latest Profile Posts

Bathrooms are not designed for the middle of the night.
Entry #11 - The someone with tentacles is back! so... I decided since a park was an area in my game... here's an enemy that's slide with a hand behind it. cause why not.
Hot chocolate and music make studying and note-taking much easier Until my hand cramps up from writing too much!
Doing RPG Maker News for 21st September 2021