Logo

Programming-Idioms

History of Idiom 81 > diff from v39 to v40

Edit summary for version 40 by lukems:
New Lua implementation by user [lukems]

Version 39

2017-10-18, 23:06:48

Version 40

2017-12-08, 14:15:59

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