math.round()

Type Function
Library math.*
Return value Number
Revision 2017.3060
Keywords round
See also math.ceil()
math.floor()

Overview

Rounds number to the nearest integer following the same rules as the JavaScript version, i.e. if the fractional portion of number is 0.5 or greater, the argument is rounded to the next higher integer. If the fractional portion of number is less than 0.5, the argument is rounded to the next lower integer.

Syntax

math.round( x )
x (required)

Number. The number to round.

Example

print( math.round( 0.1 ) )   -- Output: 0
print( math.round( 0.5 ) )   -- Output: 1
print( math.round( 8.9 ) )   -- Output: 9 
print( math.round( -0.1 ) )  -- Output: 0
print( math.round( -0.5 ) )  -- Output: 0
print( math.round( -8.9 ) )  -- Output: -9