Prevent decimal numbers from showing?

I made a skill that swaps the target's HP with MP (full version in the screenshot), but it starts showing decimal numbers after using, and after a while it just spirals out of control. I haven't had this happen with any other skills; anything that can be done to force it round up/down to the nearest one to prevent decimals from showing?

RAjHSJT.png
.to_i

Put this at the end of your calculations in the script.

edit: Or rather, in the damage calculations.
I just tried that, but it didn't seem to do anything. The formulae with that part added to it looks like this:

Code:
c=b.hp;d=b.mp;b.hp=d*1.5;b.mp=c*0.75;0.to_i
You misunderstood - it needs to be applied to the number or variable that has the decimals.

The decimals are showing because that number got converted to float at some time, and it needs to be converted back to integer to solve the problem.

So you need to write

b.hp.to_i; b.mp.to_iat the end of that damage formula, because the calculation with the 1.5 or 0.75 turns both those values into floats with decimals.
Okay, I don't get that because I have other skills that work with percentages and simply get rounded up/down accordingly.

Also, I tried to add that bit to the HP and MP, but now the skill takes like 50% of the character's HP and drains MP to 0 on the first cast.

Also, not sure if I was supposed to add the .to_i in the first part or the second part, neither worked, and adding it to both didn't do anything different (messes up either way):

Code:
c=b.hp.to_i;d=b.mp.to_i;b.hp=d*1.5.to_i;b.mp=c*0.75.to_i;0
Where did it get converted to a float? Find the REAL cause of the problem and fix it, rather than applying bandaids to cover things up.


Did you make a script change? Did you add a new script method for a damage formula? Did you have a damage formula that converts something to a float? THERE is where you need to convert it to an integer.
I have made a few minor script edits (such as removing the Item command in combat), but nothing that should mess with the way numbers show up. I have 3 scripts related to combat, one to show enemy HP/MP bars, one that removes the Fight/Escape part at the start of a battle, and the third only activates if a character is inflicted with a condition and is unrelated to the skill I'm using here.

I already had those in much earlier, and it's never shown me decimals before. For example, a skill that I have that heals for 20%HP, is still getting rounded up/down automatically, not showing decimals.
The key is that you need to find the places where you used decimals. Only those will cause the error, because those will convert the data to convert to float

a=HP/5;     // no decimal, will not cause errorsa=HP*0.2;   // contains decimals, will cause the value of a to become floata=HP/5.0;   // contains decimals, will cause the value of a to become floatThe results of all three formulae are the same, but only the first will keep the values without decimals.

And as soon as any one value has become float, it will convert all other values it is used together with
I changed the formulae to this, and it's not showing decimals any longer. 🙂

Code:
c=b.hp;d=b.mp;b.hp=d*15/10;b.mp=c*75/100;0
You could have stuck with the previous version, but you needed to add brackets to do the calculations correctly:

Code:
c=b.hp;d=b.mp;b.hp=(d*1.5).to_i;b.mp=(c*0.75).to_i;0

Original thread: https://forums.rpgmakerweb.com/threads/prevent-decimal-numbers-from-showing.45738/