So I’ve been messing around with Vector2s and noticed that when I execute the following example code
local pos1 = Vector2.new(0,0) pos1 = pos1 + Vector2.new(.2,0) print(pos1.X .. "," .. pos1.Y)
the output is
I searched the forums and found that there was no built-in fix to this issue, so I was wondering what the agreed-upon solution to these errors was?
My first thought was to round to the nearest tenth or hundredth of a digit. However, the implementation I’m thinking of in my head looks a bit inelegant:
local value = 0.20000000298023 --Pretend this is any number local decimal = (value*100) - math.floor(value*100) if decimal >= .5 then value = math.ceil(value*100)/100 else value = math.floor(value*100)/100 end --Note that I haven't actually tested this code it's just to illustrate where my mind was heading with this solution.
Is there a better way to handle this?