Hello there! Im trying to use EternityNum for my game, but I am experiencing the same problem as years ago. EternityNum adds .99 to numbers when adding regular numbers which are less than 1000. I tried multiple solutions, but it did not work for me.
As an example i can provide this:
et.bnumtostr(et.add(0;37, 0;1)) → 0;37.99999999999999
or
et.bnumtofloat(et.add(0;37, 0;1)) → 37.99999999999999
1 Like
I don’t understand what your code examples say? Assuming 0;1
means 0.1
, 0.1 has no exact float representation, which I know because 0.2 (1/5) doesn’t either. So the results you are seeing are correct, just not what you want.
1 Like
I found out my own solution for this (after the 3 AM coding session ended and i got some sleep lol).
I was adding values incorrectly into the data of the player (I mean without making sure the numbers don’t have .999… “bug” in the data itself).
My own solution to this is this:
Server side (just to do the math for the numbers less than 1000 and make sure they will not get .999… after them):
local et = require(game.ReplicatedStorage.EternityNum)
if et.meeq(value1, "0;1000") then
valueFromData = et.bnumtostr(et.add(valueFromData, value2))
else
valueFromData = et.bnumtofloat(et.add(valueFromData, value2))
end
Client side (displaying):
local et = require(game.ReplicatedStorage.EternityNum)
if et.meeq(value1, "0;1000") then
label.Text = et.short(valueFromData) --will display like 1k / 1M / 1B and etc. , will just show abbreviated number
else
label.Text = et.bnumtofloat(valueFromData) --will display like 1 / 100 / 500 and etc. , regular numbers
end
1 Like
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.