std-method

Floating-point trunc and fract

Separate a signed measurement into its whole and fractional parts; the fractional part keeps its direction from zero. Expected stdout (not executed): -7 -0.75 Common mistake: The fractional part of a negative value need not be positive.

Formal Syntax & Structure

rust syntaxrust
x.trunc() -> f64; x.fract() -> f64

Working Example

Example Snippetrust
fn main() {    let x = -7.75_f64;    println!("{} {}", x.trunc(), x.fract());}
Rust Reference