Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I round a decimal to the nearest whole number?

I'm making a quest system and I want the player to receive half of what the quest wants the player to get in money.

local plr = game.Players.LocalPlayer
local q = plr:WaitForChild("QuestGrass")
local qa = plr:WaitForChild("QuestActive")

script.Parent.Changed:Connect(function()
	script.Parent.TextArea.Text = "Hey there can you get me " .. q.Value .. " Grass and I'll give you $" .. q.Value/2     .. " in return"
end)

1 comment

0

math.floor()

1 answer

✓ Accepted answer

To round numbers, you simply use the math.floor or math.ceil methods.

In a script, if you wanted to lets say round UP the value 0.5 you would use math.ceil. A good way to remember this is ceilings are UP hence math.ceil.

If you wanted to round DOWN a value lets say 2.2 you would use math.floor. You can remember this because floors are DOWN hence math.floor.

Hope this helps :)

This discussion is preserved as it was. New answers, comments, and votes are closed.