Rounding numbers off of a value

You could say I’m quite stupid at maths.

But this thing is quite annoying.
How do I fix this?
I don’t want decimal numbers, I want a SurfaceGui slider that goes from 0 to 300, without decimals.
Example: https://gyazo.com/0b08430efa6af63db7abda9cf40e333c

local Number = script.Parent.Parent.Int

mouse = false
script.Parent.MouseButton1Down:Connect(function() mouse = true end)
script.Parent.MouseButton1Up:Connect(function() mouse = false end)
script.Parent.MouseLeave:Connect(function(x,y) mouse = false end)
script.Parent.MouseMoved:Connect(function(x,y) if mouse then 
		if 300-(((y-script.Parent.AbsolutePosition.Y)/2200)*300) > 2 then
			script.Parent.Int.Value = 300-(((y-script.Parent.AbsolutePosition.Y)/2200)*300)
		else
			script.Parent.Int.Value = 0 
		end 
		script.Parent.Bar.Size = UDim2.new(1, 0, ((1-((y-script.Parent.AbsolutePosition.Y)/2200))), 0)
	end
end)
script.Parent.Int.Changed:Connect(function()
	script.Parent.Bar.Size = UDim2.new(1, 0, (script.Parent.Int.Value/2)/50, 0) Number.Text = script.Parent.Int.Value
end)

you can use Math.Floor(Number + 0.5) to round number up

You can round the number with math.floor or math.ceil

The math library has 2 functions that allows you to round down, or up (math.floor and math.ceil)

math.floor(1.3) -- 1
math.floor(5.32) -- 5

math.ceil(1.3) -- 2
math.ceil(5.32) -- 6
1 Like

How can I detect if the decimal is below or higher than a certain point like number.5 in order to get the correct number…?

use the solution that these people provided

I don’t think thats necessary, math.floor are the most common function to round numbers down

I saw, but I need to have a detection whether it’s below .5 or higher than .5, since I would need both math.floor and math.ceil for this…

1 Like

as @gamingvn132 said you can use math.floor(number+0.5) that will make it so if number is like 10.4 its gonna be 10 while if its 10.5 its gonna be 11.

Gotcha, now I got my thing that I needed. Thanks.

Regarding this question exactly, you can do it like this:

local function frac(number)
    return number - math.floor(number)
end

if frac(number) < 0.5 then
    print("The decimal is less than 0.5")
else
    print("The decimal is greater than or equal to 0.5")
end