Logo

Programming-Idioms

History of Idiom 81 > diff from v40 to v41

Edit summary for version 41 by lukems:
[Lua] shorter

Version 40

2017-12-08, 14:15:59

Version 41

2017-12-08, 14:17:04

Idiom #81 Round floating point number to integer

Declare integer y and initialize it with the rounded value of floating point number x .
Ties (when the fractional part of x is exactly .5) must be rounded up (to positive infinity).

Idiom #81 Round floating point number to integer

Declare integer y and initialize it with the rounded value of floating point number x .
Ties (when the fractional part of x is exactly .5) must be rounded up (to positive infinity).

Code
function round(float)
    return math.floor(float + 0.5)
end
Code
function round(float)
    return math.floor(float + .5)
end