Addition in number value not working properly

Simple issue, hopefully a simple fix too.
`local Charge = script.Parent.Teleport.Charge

while true do
Charge.Value += 0.01
print(Charge.Value)
wait(0.1)
end`

Seems simple enough but whenever the script is ran, the value ends up returning
0.13, 0.14, 0.15000000000000002, 0.16000000000000003 and so on

I can’t figure out why its adding such a small amount, but its breaking the script & I can’t figure out how to round it to 0.01
Original value is 0.1, but the value slightly changes when set to 0

I tested this on a blank world and the numbers were still off, but it was more consistent than the other one. Also, even if its not in a loop it will still be off.

1 Like

Just try

Charge.Value = Charge.Value + 0.001
1 Like

That does the same thing lol, just 1/10 the original value

1 Like

The main problem is that there is no exact floating point representation of 0.01 In order to represent an infinite number of numbers, computers must employ a finite number of bits. Several frequently used numbers, like 0.01, are not included in the standard format. When you see 0.01 displayed somewhere, it means that an algorithm decided that parsing 0.01 would yield the same binary value as whatever the slightly different value would be.

1 Like

I think the problem is with the wait() use task.wait() instead. I don’t know if it would work.