Type Function Library math.* Return value Number Revision Release 2024.3703 Keywords round See also math.ceil() math.floor()
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.
math.round( x )
Number. The number to round.
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