You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
A: i want to round out some numbers in a gui so its easier to be read
What is the issue? Include screenshots / videos if possible!
A: i cant get the gui to round out these numbers in it, i tried using math.floor and math.ceil but nothing changed.
(Sorry for the low quality, i work on a 1360x768 laptop screen.)
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
A: as i said earlier, i tried using math.floor, math.ceil and other things i found on the devforum, but my gui always keeps saying, for example: .999999999999999999978 (as shown above in the screenshot, same with the tires)
here is the part of the code that measures the fuel.
and here is the one that updates the text.
im a little new to doing math in code, so i cant wrap my head around what i can do to fix this.
this is also my very first post so i apologize if i did anything wrong by posting this.
This thread mentions the same issue. It might be unfixable, but I refuse to believe it, as there are plenty of games having similar mechanic to yours and they work fine.
Actually I had the same problem 3-4 months ago and found this post with the solution.
local dec = 2
local function round_to_nearest_num(num, dec)
dec = dec or 1
local k = 10^dec
return math.round(num*k)/k
end
print(round_to_nearest_num(1693.99999999999999, dec)) -- 1694
print(round_to_nearest_num(0.6777777777777, dec)) -- 0.68
print(round_to_nearest_num(1.911111111, dec)) -- 1.91