Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

NumberValue going down by something like 0.0000000001?

Asked by 7 years ago

Lets say I use this code: p.leaderstats.Money.Value = 200.1 it should set the players money to 200.1, correct? Now the leaderboard will indeed say 200.1, however if the money has something subtracted from it, or if I go into the player, and check the value myself, it will equal 200.09999999999999. Does anyone know why? The leaderboard code does not do anything to the value of it.

1 answer

Log in to vote
1
Answered by 7 years ago
Edited 7 years ago

Floating-point errors. In exchange for a larger range of numbers, computers sacrifice the ability to represent a large amount of numbers exactly (especially decimals). This can have issues when checking for equality, but this can be resolved by factoring in a very small number, often called Epsilon.

ROBLOX uses doubles, so can represent integer numbers exactly up to something like +/- 1000000000000000 (according to a simple test that I ran)

https://en.wikipedia.org/wiki/Floating_point https://en.wikipedia.org/wiki/Machine_epsilon

0
So is there a way for me to actually make it 200.1, as adding something to it is very odd. FrostTaco 90 — 7y
0
There is no way. 200.1 cannot be represented in floating-point format. It will probably not affect you, anyway. SwardGames 325 — 7y
Ad

Answer this question