2 equal numbers somehow returning crazy high number

print(BallPercentage, CentrePercentage)
print(BallPercentage - CentrePercentage)

And the output returns
08:29:03.660 0.3 0.3 - Client - MiningControl:73
08:29:03.661 -1.6653345369377e-16 - Client - MiningControl:74

I’m stumped how if both numbers == 0.3, then why subtracting them isn’t equaling 0 and I get some extravagant random number?

Here’s how I set both those numbers

CentrePercentage = math.random(1, 9) / 10 -- Set CentrePercentage

local Location = 0
while true do
	if Pause then
		wait(0.25)
	end
			
	Location += Speed
	BallPercentage = Location -- Set BallPercentage
end

it`s not crazy high “-1.6653345369377e-16” is actualy
-0.00000000000000016653345369377

it has something to do with how math is being handled in this game. but I don’t know the exact details.

The number is just scientific notation for a really small decimal.

It is not exactly zero, most likely because of floating point errors.

1 Like

Maybe its because of this

1 Like

Yeah, floating point errors do that.
If you can try to use eighths in decimal form. Binary computers handle them better.
1/8 = .125
2/8 = 1/4 = .25
3/8 = .375
4/8 = 1/2 = .5
5/8 = .625
6/8 = 3/4 = .75
7/8 = .875
8/8 = 1