Math.floor is not correct

So I have a script that checks when the Y velocity of the humanoidrootpart is below the last velocity
When printing the velocity it gives me -0.1 but when using math.floor it gives me -1. Is there any way to fix this?

local downco = (game.ReplicatedStorage.AKM.HumanoidRootPart.Hands.C0 + game.ReplicatedStorage.AKM.HumanoidRootPart.Hands.C0.UpVector * 0.4) * CFrame.Angles(math.rad(-6),0,0)
local upco = (game.ReplicatedStorage.AKM.HumanoidRootPart.Hands.C0 + game.ReplicatedStorage.AKM.HumanoidRootPart.Hands.C0.UpVector * -0.4) * CFrame.Angles(math.rad(-3),0,0)
local co = game.ReplicatedStorage.AKM.HumanoidRootPart.Hands.C0
local upbool = false
local downbool = false
local normalbool = true
------------------------------------------------------------
local currentvel = 0
game:GetService("RunService").RenderStepped:Connect(function()
	print((char.HumanoidRootPart.Velocity.Y))
	if math.floor(char.HumanoidRootPart.Velocity.Y) > currentvel and upbool == false then
		upbool = true
		downbool = false
		normalbool = false
		
		spawn(function()
		for i = 5,1,-1 do
		akm.HumanoidRootPart.Hands.C0 = akm.HumanoidRootPart.Hands.C0:Lerp(upco,1/5)
		end
		end)
		
	elseif math.floor(char.HumanoidRootPart.Velocity.Y) < currentvel and downbool == false then
		upbool = false
		downbool = true
		normalbool = false
		
		spawn(function()
		for i = 5,1,-1 do
			akm.HumanoidRootPart.Hands.C0 = akm.HumanoidRootPart.Hands.C0:Lerp(downco,1/5)
		end
		end)
		
	elseif math.floor(char.HumanoidRootPart.Velocity.Y) == 0 and normalbool == false then
		upbool = false
		downbool = false
		normalbool = true
		
		spawn(function()
		for i = 5,1,-1 do
			akm.HumanoidRootPart.Hands.C0 = akm.HumanoidRootPart.Hands.C0:Lerp(co,1/5)
		end
		end)
		
	end
	currentvel = (char.HumanoidRootPart.Velocity.Y)
    end)

that is how numbers work
-1 is lower then 0

if you want -0.1 to turn into 0 try math.ceil()

2 Likes

As a more detailed explanation to what @D0RYU said, math.floor rounds down, meaning whether it would be rounded down normally or not, it will round down. math.ceil rounds up.

thats a problem since, if I do 0.1 it gives me 1 which I dont want, I want 0 in that case

I want to round to the nearest whole number not the nearest largest whole number

How do I round normally? there seems to be no way.

math.round() is literally perfect for this then

1 Like

Then just add a if statement like this:

if number > 0 then
number = math.floor(number)
else
number = math.ceil(number)
end

I will check it out, give me a second