How can I round to the nearest Hundredths place?

Hi, there,
I want to round my number to the nearest Hundredths place. Keep in mind it doesn’t always need to be rounded though, because sometimes it is in the hundredths or tenths place already. Here is an example on what I am meaning:

Script in Serverscriptservice

game.ReplicatedStorage.d.OnServerEvent:Connect(function(plr)
	local ui = plr.PlayerGui.uiPAGE.Frame.vvvv
	local text = plr.PlayerGui.uiPAGE.Frame.TextLabel
	
	ui.Value = 1.77--This is probably not needed I will remove later
	while true do
		task.wait(2)
		ui.Value += 1.77
		text.Text = "Cost "..ui.Value
	end
end)
ui.Value = math.round(ui.Value * 100) / 100

-- Optionally add trailing zero
text.Text = string.format("Cost %0.2f", ui.Value)
5 Likes

I’m not sure there are any methods but we could do this in a very strange way.

  • Convert the number into a string
  • Then string.gsub can remove the other numbers
  • then we can convert it back into a number and use it

There’s obviously better ways to do this of course but I can’t think of any atm.

Thank you for your help!! :grinning:

This text will be blurred

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