Is it possible to round all damage to not have any decimals show up using Javascript? I don't mind using some of Yanfly's scripts if that helps.
Rounding decimals
RPG Maker MV SupportDoesn't the default damage formula do that already? If not, encase the formula in Math.floor() or Math.ceil() to round up or down. Or simply use Math.round(). For instance:
Math.round(a.atk * 4 - b.def * 2)
Math.round(a.atk * 4 - b.def * 2)
I tried that but for some reason it still doesn't work.
Math.floor() - rounds value up (e.g x = 2 * PI - return 6.28 and Math.floor return 7)
Math.ceil() - rounds value down (e.g x = 2 * PI - return 6.28 and Math.floor return 6)
PI = 3.14
If Math.round(x) doesn't work, check your formula and variables, probably you have empty variable or error in formula (show us console - F8)
Math.ceil() - rounds value down (e.g x = 2 * PI - return 6.28 and Math.floor return 6)
PI = 3.14
If Math.round(x) doesn't work, check your formula and variables, probably you have empty variable or error in formula (show us console - F8)
By default the damage formula is evaluated, capped to a minimum of zero based on damage type, then rounded to the nearest integer. Are you using any plugins, and what exactly is in your formula box?
Just for reference, parseInt is an alternative that works by truncation (i.e. it ignores the decimal part). E.g. parseInt(35.852) returns 35.
Just for reference, parseInt is an alternative that works by truncation (i.e. it ignores the decimal part). E.g. parseInt(35.852) returns 35.
Other way around (for positive values), see Math.floor() and Math.ceil(). Floor brings it down to the floor, ceil moves it up to the ceiling. ^_^
Actually I am using plugins, particularly Yanfly's Buffs&States manager as well as some of his other scripts. I figured just asking for the java code would work that's why I didn't really mention it. But basically what I was trying to do(I already found a work around that is not quite as ideal) was reduce the damage someone takes if the opponent dishing the damage was affected by a certain passive state. My example is below:
<Custom React Effect>
if (user.isStateAffected(386)) {
value *= 0.7;
}
if (user.isStateAffected(387)) {
value *= 0.5;
}
</Custom React Effect>
However when I do this it never rounds the damage(it shows something like 128.99999998). If there is no basic syntax fix to this then don't worry about it.
<Custom React Effect>
if (user.isStateAffected(386)) {
value *= 0.7;
}
if (user.isStateAffected(387)) {
value *= 0.5;
}
</Custom React Effect>
However when I do this it never rounds the damage(it shows something like 128.99999998). If there is no basic syntax fix to this then don't worry about it.
Do this:
<Custom React Effect>
if (user.isStateAffected(386)) {
value *= 0.7;
value = Math.round(value);
}
if (user.isStateAffected(387)) {
value *= 0.5;
value = Math.round(value);
}
</Custom React Effect>
<Custom React Effect>
if (user.isStateAffected(386)) {
value *= 0.7;
value = Math.round(value);
}
if (user.isStateAffected(387)) {
value *= 0.5;
value = Math.round(value);
}
</Custom React Effect>
It works! Thank you.
Happy to help.🙂
Original thread: https://forums.rpgmakerweb.com/threads/rounding-decimals.95730/