Logo

Programming-Idioms

History of Idiom 81 > diff from v53 to v54

Edit summary for version 54 by programming-idioms.org:
[Rust] Avoid link shortener if possible

Version 53

2019-12-28, 21:13:16

Version 54

2020-03-20, 17:51:21

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;
Code
let y = x.round() as i64;
Doc URL
https://doc.rust-lang.org/std/primitive.f64.html#method.round
Doc URL
https://doc.rust-lang.org/std/primitive.f64.html#method.round
Demo URL
https://is.gd/syPIQE
Demo URL
https://play.rust-lang.org/?version=stable&mode=debug&edition=2015&gist=8f83117f3a6433fe09a20f2a3813d621