std-method

Floating-point round and round_ties_even

Choose a rounding rule explicitly. At exact halfway values round moves away from zero, while round_ties_even chooses the even integer. Expected stdout (not executed): 3 2 4 4 -3 -2 Common mistake: Do not assume all decimal-looking ties remain exact after arithmetic.

Formal Syntax & Structure

rust syntaxrust
x.round() -> f64; x.round_ties_even() -> f64

Working Example

Example Snippetrust
fn main() {    for x in [2.5_f64, 3.5, -2.5] { println!("{} {}", x.round(), x.round_ties_even());    }}
Rust Reference