×
A new build of Corona SDK is now available to subscribers. Not a subscriber? Subscribe now.
CoronaSDK 2014.2281 | Released: 24 Apr 2014, 1:58am | What's New | Download Now

math.round()

Description:

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

Syntax:

local value = math.round( num )

Example:

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

Parameters:

num
Number to be rounded.

Returns:

number
Number rounded up or down.

Remarks:
Supported on operating systems and platforms for build numbers shown:
  • Mac OS X:
    Build 2011.514
  • Windows:
    Build 2011.514
  • iOS:
    Build 2011.514
  • Android:
    Build 2011.514

Replies

efraim6
User offline. Last seen 2 years 41 weeks ago. Offline
Joined: 25 Jun 2011

I don't think math.round is supported anymore. It gives me big greasy errors. I used math.floor instead.

-E

komirad
User offline. Last seen 1 year 46 weeks ago. Offline
Joined: 12 Jul 2011

Why is round not supported..

Tom
User offline. Last seen 16 hours 52 min ago. Offline
Staff
Joined: 13 Jul 2010

It's supported in the Daily builds and will be available in the next public release.