math.Round

From GMod Wiki

Jump to: navigation, search
Function
Syntax math.Round( Float value [, Integer decimals] )
Where is this used?
Description:
Return value rounded to the nearest whole number. Anything less than 0.5 gets rounded down, and anything greater than or equal to 0.5 gets rounded up.
Returns: Integer
Part of Library: Math
Realm: NewerShared.png
BBCode Link: [b][url=http://wiki.garrysmod.com/?title=Math.Round]Math.Round [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]



Example

DescriptionRounds 0.1 down and 0.6 up.
Used onNewerShared.png
Code
print(math.Round(0.1))
print(math.Round(0.6))
Output0
1


Example

DescriptionRounds the players velocity.
Used onNewerShared.png
Code
local speed = ply:GetVelocity():Length()
math.Round(speed)
// Would round the persons speed so it isn't like 250.34543525253))
Output250


Additional Notes

See Also

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox