How to convert float to integer?

Hi, I would like to convert a float to integer, like rounding 11.61 to 12.

The problem is that the output result is a float, this would break the shape of my scripts as they use integers, as I said I researched how to convert float to integer but I didn’t find anything useful. And I came to devforum for any help.

Script:

-- Bank = math.Random
local Bank = game.ServerStorage.Configuration.Bank.Value -- Integer Value

function Func_Saldo_Reset()
	local Num = Bank / 2 - Bank / 3
	while Num > 5000 do -- Check if the result is under 5000 then proceed
		Num = Num / 2
	end
    -- if "Num" is a float then convert to integer
	Bank -= Num
    warn(Num)
end

Func_Saldo_Reset()

Output
image convert to 4173

Any help is welcome!

1 Like
local float = 4172.83333333
local int = math.ceil(float)

math.ceil will round up while math.floor will round down

math wiki

6 Likes

math.round is also an option that you can use to round

3 Likes

lol i didnt even know that existed

yea i also didnt realise until my friend told me. for some reason it doesnt appear in the scripting hints so i thought it doesnt exist
image
image
image

1 Like

this is the reason why you look at the api

2 Likes