Logo

Programming-Idioms

History of Idiom 81 > diff from v42 to v43

Edit summary for version 43 by programming-idioms.org:
Admin deletes impl 1827

Version 42

2018-01-26, 19:55:55

Version 43

2018-01-27, 12:38:50

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).

Imports
import math
Code
y = float(y)
x = math.floor(y+0.5)