Hi, recently I’ve had a problem with GUI where trying to display decimals just does not work. In my game, money can have decimal points, but whenever a decimal is displayed, instead of displaying 4.9 for example, it displays ‘4.8999999999999,’ to the point where it goes off of the screen and makes it impossible to see how much money you actually have.
Your money is stored on the server in a NumberValue, and whenever it gets changed a RemoteEvent gets fired to the player to update the GUI.
This is the code running on the server side:
game.ReplicatedStorage.serve.OnServerEvent:Connect(function(player, p, t, liking)
print(p)
if p == 1 then
p1off = true
game.Workspace.p1values["t"..t.."stock"].Value -= 1
game.Workspace.p1values.money.Value += (3+(liking/10))
game.ReplicatedStorage.serve:FireClient(player, (3+(liking/10)))
player.leaderstats.Money.Value = game.Workspace.p1values.money.Value
end
end)
The simple way would be to multiply the number to be whole, and then divide it after you round the number
lets say you have the number 4.89, multiply by 10, you will get 48.9, you can then round the number as a whole, which will give you 49, you then divide by 10, which will give you 4.9
You can do the Inverse of the Multiplication and the Division here to get the same Result, by Dividing the Number by 0.1, and Multiply by 0.1, but this comes with more precision issues
Edit: math.round() will give you a result of 49, and will change depending on the decimal point, and its amount, math.ceil() will always give you 49 no matter the decimal’s amount (ceil rounds up), and math.floor() will give you 48, no matter the deimals amount (floor rounds down).
You can use string formatting to set how many decimal places to show. This example will use two decimal places i.e. “123.00” if 123, and “12.35” if 12.345