Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to make the magnitude not float ?


function OnChanged(Property)
	if Property == "Velocity" then
		print(game.Workspace.Part.Velocity.Magnitude)
	end
end

game.Workspace.Part.Changed:Connect(OnChanged)

I was hoping it print 10 , 20 or 5 but it print a float value like 1.263478337.

So how do i make it so it print only the number and not a float value ?

(Sorry for my bad grammar.)

2 answers

As clime said, the math.floor and math.ceil functions are good. you may also try math.floor(num+0.5) for a good alternative. Values like 1.5, 2.5, etc will be rounded up to 2, and 3. Values like 1.4 and 2,4 would become 1, and 2.

function round(num)
return math.floor(num+0.5)
end
print(round(1.4))
print(round(1.5))
print(math.floor(1.8+0.5))
print(math.floor(1.4))
print(math.ceil(1.4))

Output:

1
2
2
1
2

This discussion is preserved as it was. New answers, comments, and votes are closed.