How do I round up a TextLabel?

Hello, I tried to round up a TextLabel to 1 decimal but it didn’t work.
The value gets rounded up (1.4) but on the TextLabel it’s displayed as 1.400000000001 or something similar.

Note: The value.Value is the same as text.Text
This is my code:

local startergui = script.Parent.Parent
local frame = script.Parent
local button = frame.TextButton
local clicks = startergui:WaitForChild("Clicks")
local value = startergui:WaitForChild("Value")
local price = script.Parent:WaitForChild("Value")
local text = startergui:WaitForChild("TextLabel")

function roundNumber(num, numDecimalPlaces)
	return tonumber(string.format("%." .. (numDecimalPlaces or 0) .. "f", num))
end

task.spawn(function()
	while true do
		value.Value = value.Value + clicks.Value
		roundNumber(text.Text, 1)
		wait(1)
	end
end)
1 Like

Hi, I would reccomend when rounding using

math.round()

Here is a better way to round to a decimal place:

local function roundNumber(number, decimalPlaces)
    return math.round(number * 10^decimalPlaces) * 10^-decimalPlaces
end
1 Like

youre not actually changing the text

local startergui = script.Parent.Parent
local frame = script.Parent
local button = frame.TextButton
local clicks = startergui:WaitForChild("Clicks")
local value = startergui:WaitForChild("Value")
local price = script.Parent:WaitForChild("Value")
local text = startergui:WaitForChild("TextLabel")

function roundNumber(num, numDecimalPlaces)
	return tonumber(string.format("%." .. (numDecimalPlaces or 0) .. "f", num))
end

task.spawn(function()
	while true do
		value.Value = value.Value + clicks.Value
		text.Text = tostring(roundNumber(text.Text, 1))
		wait(1)
	end
end)
1 Like