Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make the magnitude not float ?

Asked by 5 years ago

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

Log in to vote
2
Answered by 5 years ago
Edited 5 years ago

All of these are useful for you probably:

wiki.roblox.com/index.php?title=Global_namespace/Mathematical_functions

math.floor() -- Round down

math.ceil() -- Round up

-- example

local decimal = 10.5151534534654
math.floor(decimal)
print(decimal)

-- output:
10
Ad
Log in to vote
0
Answered by 5 years ago

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

Answer this question