1 - 0.8 = 0.19999999999999996?

So, my script calculates the cooldown of the object - the cooldown after the upgrade. although, my calculations seem to be incorrect.

			gui.Selection.CooldownAfterUpgrade.Text = "-"..(config.Cooldown.Value - config.UpgradedStats.Cooldown.Value)

Floating point inaccuracies. The method used internally to calculate the values are not 100% accurate (the floating point representation only has so much precision).

Just round the value or truncate it.

rounding it only seems to round it to the nearest whole number. I need it to round to the nearest decimal.

There are formulas to do that. They are easily available online

Simple.

local NewNumber = math.round(Number * 10) / 10

This will prevent the issue of Whole Numbers for you. Need more decimal places? Use Powers of 10. (10, 100, 1000, 10000 etc.)

4 Likes

Math.round(num * 10) /10

Rounds to 1 decimal place

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.