Logo

Programming-Idioms

History of Idiom 81 > diff from v28 to v29

Edit summary for version 29 by Reiner Martin:
New Rust implementation by user [Reiner Martin]

Version 28

2016-04-21, 11:03:29

Version 29

2016-08-11, 20:36:00

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
let y = x.round() as i64;
Doc URL
https://doc.rust-lang.org/std/primitive.f64.html#method.round
Demo URL
https://is.gd/syPIQE