Quick question about rounding problems

I have a set of skills that heal a set percentage of hp and mp to the user. The script call I pieced together is

if ($gameSwitches.value(271)) {

var actor = $gameActors.actor(1);

actor.gainHp(0.25 * actor.mhp);

actor.gainMp(0.15 * actor.mmp);

}

and that works like a charm. Except now I end up with hp and mp that's displayed with decimal points, like if I have 10 hp and heal 25% I end up with 12.5 hp. I've never seen that before. Any way to get rid of that?
Math.round() will round in the typical fashion. Math.floor() will always round down, and Math.ceil() will always round up.

Code:
actor.gainHp(Math.round(.25 * actor.mhp));

As a side tip, you should always post code in the CODE tags (the </> on the edit bar) as it preserves indentation and brackets.
Wow that was quick. Thanks, that did the trick 🙂
I'll keep that in mind for the inevitable next problem I'll stumble into.
Thank you!
Very cool. I need to keep track of this as well.

But for my own personal edification, isn't there something missing from the switch portion of the script? Like if it is "on" or "off" (true/false)?

Or does "if ($gameSwitches.value(271))" default to meaning if the switch is on?

I am still learning how to understand scripts for conditionals so I could be completely mistaken.
But for my own personal edification, isn't there something missing from the switch portion of the script? Like if it is "on" or "off" (true/false)?

Or does "if ($gameSwitches.value(271))" default to meaning if the switch is on?
An if statement resolves if the operation inside the parentheses produces a true (or truthy) value.

The function Game_Switches.value() returns a boolean value, true or false.

So just like a different function might produce a numeric value and you simply use the function as that value - let's say you stored the number 5 inside variable 42, you can do
Code:
$gameVariables.value(42) + 3
and that's exactly the same as typing 5 + 3

Similarly, if switch 271 is turned on so its value() is true, that's exactly the same as saying
Code:
if (true)
Thus, saying
Code:
if (true == true)
would be redundant.
Ah, thanks for that clarification. You just made that boolean value return concept fall into place. I learned several new things from this thread!

Original thread: https://forums.rpgmakerweb.com/threads/quick-question-about-rounding-problems.174239/