Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Riddle me this? Math is doing stupid things...

So I was doing some work with some oddly specific numbers, and found this:

While the simple:

print(0.15 - 0.15)

equals '0', this:

print(0.15000000596046 - 0.15) 

equals '5.9604600144425e-09' for some reason. It is messing up my script, and driving me crazy. Any ideas?

5 comments

0

That's how computers work. The further away from 0, the less accurate.

0

The outcome of the second equation is correct. It's called scientific notation.

0

use math.floor() or math.ceil() math.floor rounds the number down and math.ceil rounds the number up

0

Do you want to know how to disable e-notation?

0

I already asked that question, search questions simular to yours before asking

2 answers

5.9604600144425e-09 equals 5.9604600144425*10^-9. It's called scientific notation, and is used for dealing with really small/large numbers.

I can't think of any solution other than just not using 0.15000000596046.

You can remove that e-notation. Watch this:

local str = "0.15000000596046"
local editedstr = string.format(".0f", str)
local num = tonumber(editedstr)
print(num - 0.15) 

2 comments

0

% -- 18 (the % part goes directly next to 18.)

0

in line 2

This discussion is preserved as it was. New answers, comments, and votes are closed.