math.Round
From GMod Wiki
Revision as of 17:27, 12 November 2011 by TheFreeman193 (Talk | contribs)
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: | |
BBCode Link: | [b][url=http://wiki.garrysmod.com/?title=Math.Round]Math.Round [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] |
Example
Description | Rounds 0.1 down and 0.6 up. |
---|---|
Used on | |
Code | print(math.Round(0.1)) print(math.Round(0.6)) |
Output | 0 1 |
Example
Description | Rounds the players velocity. |
---|---|
Used on | |
Code | local speed = ply:GetVelocity():Length() math.Round(speed) // Would round the persons speed so it isn't like 250.34543525253)) |
Output | 250 |
Additional Notes
- The decimals argument lets you decide which decimal point you want to round to. math.Round(1.234, 2) would be rounded to 1.23.