Changing the HP into a decimal

Hey,

i am working on a project for teaching purposes. The idea is, that the player needs to do exact the HP of the enemies as damage in order to win battles. The Attacks must always deal damage in decimals (for example a tenth of the max hp or a triple of the current hp).
My Problem ist that the HP are not decimals, so i run into problems if i, say, want to subtract a third of the HP twice. The game rounds the Enemy HP, if they got 100 max HP, to 32. Now a third attack, dealing again a third of the max HP, wont kill, because it deals 33.3 damage, not 32.
Is there any way to change the HP into a decimal or a other way to bypass this problem?
you can change it to digit's without problem, but what you want more
is the dmg into padZero(1) or a padZero(2) to make this happen.

how the battle is done require how to code this and to change the formula
to take decimal damage if it's not the default way.

so there are some changes required for it (depending on the plugin and
the way your battle system works)
As a side note, I think the Math.round() function is there to prevent float issues as well in damage. You'll still have to limit it like Shadow suggested.

Here is what 100 / 3 gives me online (MDN - Javascript):
33.333333333333336

Precision is one thing and the float may or may not prevent you from achieving this.

The above requires you to be precise up to where the '6' is (position 15 after the decimal, whatever word you use for it haha), so 33.33333333333333 (fourteen 3s after the decimal) won't work.
Like @bass2yang implies, the big problem here is that JavaScript, like most general-purpose programming languages, internally represents floating-point Numbers using binary integers (IEEE 754). I.e. if a value cannot be expressed in binary (with 53-/11-bit mantissa/exponent, 1 bit per sign), then it cannot be stored exactly. This is apparent in cases like 1/3, or more famously 0.1 + 0.2 = 0.30000000000000004.

Values can easily be rounded or truncated to the required precision, e.g.
JavaScript:
Math.trunc($gameVariables.value(123) * 100) / 100
However, that sort of thing would need to be applied in various places, and as-is it does not fix problems with, for example, 1/3.

A couple of ideas:
  1. Use integers and multiply everything by an appropriate value, e.g. the HCF [edit: LCM 😴] of all divisors. The easiest solution if you're not actually teaching about decimal representation.

  2. Alternatively, find a plugin that achieves analytic precision in relevant areas, e.g. using a division algorithm or simplified computer algebra system. Pretty sure that would still need significant display changes as well, though, which could depend on any other plugins you're using.
Thanks for your help. I managed it by using integers and multiplying, as caethyril suggested.

Original thread: https://forums.rpgmakerweb.com/threads/changing-the-hp-into-a-decimal.169242/