# How to do round money to the nearest cent in Roblox?

This is happening to my game and idk why any idea how to round to nearest cent?

Doing this should work, this was a post I saw off another post, test it out.

``````local roundDecimals = function(num, places)
places = math.pow(10, places or 0)
num = num * places

if num >= 0 then
num = math.floor(num + 0.5)
else
num = math.ceil(num - 0.5)
end

return num / places
end

roundDecimals(amountOfMoney,2)
``````

What is num? idk what this is so

Use this:
`money = math.round(money *100) / 100`

it rounds your money to 2 decimal places. @maitiothmane 's version is a function in case you want to do it to multiple values in multiple places in your script.
If you are only doing it in one place then just round it like I suggested.

for your question above the last line in Proxy’s script calls the function, and sends the amountOfMoney value (just put the name of whatever your variable is for money in place of that) to the function, which uses the variable ‘num’ to do the calculations.

So would that turn 124.739999999999 into 124.73?

Would this work?

``````local money = script.Parent.Parent.ReplicatedStorage.GameData.CompanyMoney.Value

while true do
wait()
money = math.round(money *100) / 100
end

``````

No it would round it to 124.74.
it rounds 124.739999999 * 100, so 12473.999999, making it 12474, then divide it by 100, so 124.74.

Its not working. It turns out I gotta do it inside of a local script. Anyway to implement that into this script?

``````local player = game.Players.LocalPlayer

local screen = player.PlayerGui.phoneGui.phone.offScreen.screen

local playerMoney = player:WaitForChild("PlayerData").Money
local companyMoney = game.ReplicatedStorage.GameData.CompanyMoney

local labelSize = 12
local numSize = 13

local playerMoneyLabel = Instance.new("TextLabel")
playerMoneyLabel.AnchorPoint = Vector2.new(0.5,1)
playerMoneyLabel.Position = UDim2.new(0.5,0,0.25,0)
playerMoneyLabel.Name = "playerMoneyLabel"
playerMoneyLabel.Text = "Personal:"
playerMoneyLabel.BackgroundColor3 = Color3.fromRGB(176, 203, 230)
playerMoneyLabel.TextColor3 = Color3.fromRGB(0, 7, 144)
playerMoneyLabel.Size = UDim2.fromScale(1,0.125)
playerMoneyLabel.FontFace = Font.new("rbxasset://fonts/families/PressStart2P.json")
playerMoneyLabel.BorderSizePixel = 0
playerMoneyLabel.TextSize = labelSize
playerMoneyLabel.TextXAlignment = Enum.TextXAlignment.Left
playerMoneyLabel.Visible = false
playerMoneyLabel.TextWrapped = true

local selection = Instance.new("BoolValue")
selection.Parent = playerMoneyLabel
selection.Name = "selection"

local playerMoneyAmount = playerMoneyLabel:Clone()
playerMoneyAmount.Parent = playerMoneyLabel.Parent
playerMoneyAmount.Name = "playerMoneyAmount"
playerMoneyAmount.Position = UDim2.new(0.5,0,0.375,0)
playerMoneyAmount.Text = "\$" .. tostring(playerMoney.Value)
playerMoneyAmount.TextSize = numSize

local companyMoneyLabel = playerMoneyLabel:Clone()
companyMoneyLabel.Parent = playerMoneyLabel.Parent
companyMoneyLabel.Name = "companyMoneyLabel"
companyMoneyLabel.Text = "Company:"
companyMoneyLabel.Position = UDim2.new(0.5,0,0.5,0)

local companyMoneyAmount = playerMoneyLabel:Clone()
companyMoneyAmount.Parent = playerMoneyLabel.Parent
companyMoneyAmount.Name = "companyMoneyAmount"
companyMoneyAmount.Text =  "\$" .. tostring(companyMoney.Value)
companyMoneyAmount.Position = UDim2.new(0.5,0,0.625,0)
companyMoneyAmount.TextSize = numSize

playerMoney.Changed:Connect(function()
playerMoneyAmount.Text = "\$" .. tostring(playerMoney.Value)
end)

companyMoney.Changed:Connect(function()
companyMoneyAmount.Text =  "\$" .. tostring(companyMoney.Value)
end)
``````

I think this should work:

``````playerMoney.Changed:Connect(function()
playerMoney.Value = math.round(playerMoneyValue *100) / 100
playerMoneyAmount.Text = "\$" .. tostring(playerMoney.Value)
end)
``````

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