Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago

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)
0
math.floor() User#19524 175 — 6y

1 answer

Log in to vote
2
Answered by 6 years ago
Edited 6 years ago

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 :)

Ad

Answer this question