Weird Decimal Values

hey developers! i have a weird issue with stringvalues. i have an issue where i minus 0.05 off the stringvalue. sometimes, it randomly has .9999 instead of the actual number. for example, 0.8 is replaced with 0.799999. i tried to search up fixes for it but i couldn’t find any. here’s the code:

local player = script.Parent.Parent.Parent.Parent.Parent

script.Parent.MouseButton1Click:Connect(function()
	if player:FindFirstChild("leaderstats"):FindFirstChild("Cash").Value >= player:FindFirstChild("cooldownMoney").Value then
		player:FindFirstChild("leaderstats"):FindFirstChild("Cash").Value -= player:FindFirstChild("cooldownMoney").Value

		player:FindFirstChild("cooldownMoney").Value += math.random(25, 50)

		player:FindFirstChild("cooldownValue").Value -= 0.05

		game:GetService("ReplicatedStorage").remoteEvents:WaitForChild("confettiClient"):FireClient(player)
	end
end)

image_2024-11-03_132153175
image_2024-11-03_132220355
any help appreciated!

That’s a floating point precision error.
You can use string.format(%.1f, string)

3 Likes

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