A problem with round number

Hello. I tried to make the round number on my coin gui, but from 578915 i got 5,78915. How to remove all after 5,7?

Code:

local Value = game.Players.LocalPlayer.leaderstats.Coins.Value

function renew()
	if Value >= 10000 and Value < 100000 then
		parent.Text = Value /10000
	end
end

while wait(.1) do
	renew()
end```

Use math.floor for rounding, to round up to nearest whole this should work.

local function round(n)
	return math.floor(n + 0.5)
end

Can you adapt it for my code pls? :sweat_smile:

I tried to adapt it for my code, and got 6 from 578915

I believe to round to the nearest 10, you can multiply the current number by 10, round it, then divide it by 10.

Quick implementation

function RoundNumToNearestTenth(num)
	local NearestTenth = (math.round(num * 10))/10
end

Also, rather than running a loop every 0.1 seconds, you should use events, like so:

local Coins = game.Players.LocalPlayer.leaderstats.Coins

function renew()
	if Coins.Value >= 10000 and Coins.Value < 100000 then
		parent.Text = Coins.Value / 10000
	end
end

Coins.Changed:Connect(renew)
renew()
1 Like
--define the services you use
local Players = game:GetService("Players")

local Player = Players.LocalPlayer
--store the reference to the object not the value!(else it will remain constant)
local Coins = Player.leaderstats.Coins

function floor(num, decimalDigits)
	local x = 10^decimalDigits 
	return math.floor(num*x)/x
end

function renew()
	--flooring the value to 1 decimal digit
	if Coins.Value >= 10000 and Coins.Value < 100000 then
		parent.Text = floor(Coins.Value/10000, 1)
	end
end

--instead of looping, run the function every time the coins update
renew() --and also once at the start
Coins.Changed:Connect(renew)

Returned 5.8, i need this to return 5.7

Okay, just use math.floor instead of math.round

Not helped, returns so big number. I need this to return 5.7

Big thank you for help! Your code with floor helped

Sorry I thought the code related to 10000 was a method to round the number(hence why I removed it), I added it back and fixed my code snippet.