UI Visual glitch causing number to look like 0.600000000000001

I am working on an upgrades menu for my game and when players upgrade coins per second sometimes the UI will show 0.2, 0.4, ect. but then sometimes it will show it says something like 0.600000001. Obviously it is 0.6 but for some reason the game draws it all the way out. The UI text label is based of a number value Instance.

StatFrame.TextLabel.Text = player.leaderstats.CoinsPerSecond.Value

When this glitch occurs and I check what the number is in the number value it is always a regular number like 0.6 while the UI shows 0.6000000001.

I have tried round, but it doesn’t help at all.

yea it still shows a ridiculous number

It all comes down to how float numbers are handled binary-wise.
You can even do print((0.1 + 0.2) == 0.3) => false to see it happen.

As for solving it, you can use string.format like this;

Text = string.format("%.1f", Value)
3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.