problems with damage calculations

so, i recently did a little research for good damage calculations, and i came across this beauty:

a.atk * (constant / (constant + b.def))

i tested it on a calculator with some example stats, and it worked out pretty well with what i'm trying to do. however, the problem i'm facing is that this calculation does not, or rather, does no longer work in vx ace. i did a lot of testing around to feel around with the damage ranges before, and it worked just fine. now suddenly, it seems to think that the damage it is supposed to do is not even 1. the current stats that i tested it with were:

11 * (50 / (50 + 11))

which should result in 9 damage. the game, however, seems to not take the attack stat into account and only calculate what's in the brackets, because it results in the "takes no damage" message. why does this happen, and especially only now, after it worked fine literal minutes ago?
First of all, the first set of parentheses is useless and you can safely remove them. Only the ones enclosing the addition are mandatory.

The second point here is that the formula will end up returning a low value anyway. Unless you heavily increase the atk and def values... and even then the result won't be as impressive as expected.

#3 is focused on the variance. For low returned values it'll be too high. So a 9 hp damage may easily become 0. Fortunately, it won't go below 0, but without some native safeguard it could have done so.
First of all, the first set of parentheses is useless and you can safely remove them. Only the ones enclosing the addition are mandatory.

The second point here is that the formula will end up returning a low value anyway. Unless you heavily increase the atk and def values... and even then the result won't be as impressive as expected.
i've thought about the first parentheses as well and removed them before, thinking that'd be the problem, but it didn't change anything.

i know the value wouldn't be high, i'm going for lower numbers anyway just because i'm a newcomer and i want to test the waters when it comes to balancing. the problem is that even if i set the constants to 100 or higher, it will still not give me the correct results and continue to give me "took no damage" messages.
Re-read my previous post, especially reason #3.
Re-read my previous post, especially reason #3.
bloody hell that didn't even show up for me until now.
i've tried playing around with the variance already. lowered it to 10, which should never make a value of 9 go anywhere near even 1. the problem really is that vx ace does not correctly calculate this, when it had no problem with this calculation just a few tests ago.
For low returned values it'll be too high. So a 9 hp damage may easily become 0.
When I saw the screenshot, I didnt think anything was explicitly wrong. Was i incorrect in assuming variance was a percentage in ace?

I was thinking about the tested enemy's element rate for the tested weapon's element possibly being 0%
When I saw the screenshot, I didnt think anything was explicitly wrong. Was i incorrect in assuming variance was a percentage in ace?

I was thinking about the element rate for the testing weapon being 0%
well, the variance only takes that percentage of the value either away or adds to it to create varying damage output. so it'd be 10% of 9 damage, for example, so either -1 or +1 damage at random. nothing that should outright negate the entire damage.
@MortisRigor If you replace the second 50 with 50.0(aka convert it to a float), that should make the formula work correctly.
@MortisRigor If you replace the second 50 with 50.0(aka convert it to a float), that should make the formula work correctly.
i actually cannot believe that worked so easily. thank you so much, i had such a headache over this.
can you explain what a float is, so that i can understand what happened here?
can you explain what a float is, so that i can understand what happened here?
Sounds integer division. The remainder being discarded and the integer portion of the quotient being kept if both the dividend and divisor are integers. Ive spent way too much time around JS to remember it
Sounds integer division. The remainder after division being discarded if the dividend and divisor is an integer and only the whole number is kept as the quotient. Ive spent way too much time around JS to remember it
so just a case of vx ace going "woah buddy nobody told me i had to do commas in here" potentially?
Well, the variance CAN lower the damage to 0 anyway because it's a nominal value not a percentage. It doesn't mean it will always do that but it still can. Ignore that and eventually you'll get a 0 damage as your end result there.

Now that I can take a look at it on a wide screen after having a coffee, the lack of a floating number here makes sense. Ruby treats all those values as integers (no decimals included) while performing the multiplication or division UNLESS you tell it to use a float like this 1.to_f or value.to_f or 10.0

Why did it work before if you never used a float from the very beginning?

That's because you made the denominator become a larger number than the numerator. At the end of the day you gotta see it as a fraction. All fractions are divisions by default, anyways.

If the denominator had been less than or equal to the numerator, then you would have never had an issue at all.

At the end there are 2 ways to solve it. One was already provided by another forumer and the second one is to alter the fraction, especifically the denominator (the value at the bottom or right after the / division symbol there).
so just a case of vx ace going "woah buddy nobody told me i had to do commas in here" potentially?
not exactly, you would have gotten a similar result if you changed the formula to:

50 * a.atk / (50 + b.def)

your problem is a rounding error, and by forcing the engine to use float/decimal values instead of integer/whole numbers you basically disabled that rounding.

using the formula above on the other hand would make rounding the last operation, preventing it from being multiplied.

Integers are only whole numbers, all partials are automatically discarded.
so calculating with an integer example:
1) (5 / 2) * 10 => 2 * 10 => 20
2) 10 * 5 / 2 => 50 / 2 => 25

In integers the value 2.5 is stored as 2 because it is the whole number of the value, the .5 is lost
So with integer operations you should always do divisions last to minimize the rounding errors.

That is the better solution than forcing the float, because VXA also has the problem of keeping float values once converted, and if you force the float in the wrong way you'll suddenly have float values for HP and similar being displayed in the menu. And you don't want to see a status with HP: 100.0000000 instead of HP: 100

Edit: partially ninja'd

Original thread: https://forums.rpgmakerweb.com/threads/problems-with-damage-calculations.169872/