Math.round not rounding number

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to round a variable so it doesn’t clutter the GUI.
  2. What is the issue? Include screenshots / videos if possible!
    Math.round does not round the variable, it starts having decimals after the second loop.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Multiplying the variable inside the math.round does not change the variable and adding the math.round to the variable adds too much.
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

Here’s an example of what I’m trying to do.

local testcost = 1000

while true do
	testcost *= 1.25
	math.round(testcost)
	print(testcost)
	wait(0.1)
end

The output starts having decimals after the second loop.
Help is appreciated. :slightly_smiling_face:

instead of math.round use:

testcost = math.floor(testcost + .5)

You aren’t setting the variable.

local testcost = 1000

while task.wait(.1) do
	testcost = math.round(testcost * 1.25)
	print(testcost)
end
1 Like

this line is useless because

so try this

while true do
	testcost = math.round(testcost * 1.25)
	print(testcost)
	wait(0.1)
end
1 Like