primitive-type

Rust f64: 64-bit floating-point number

Use f64 for approximate fractional calculations that need more precision than f32. It uses binary64 representation and is the default inferred floating-point type when unconstrained. Expected output: 5.00 Why: The multiplication doubles an exactly representable fraction; the formatting requests two digits after the decimal point. Common mistake: Do not use ordinary binary floating point for money when exact decimal rounding rules are required.

Formal Syntax & Structure

rust syntaxrust
let name: f64 = floating_literal;

Working Example

Example Snippetrust
fn main() {    let hours: f64 = 2.5;    println!("{:.2}", hours * 2.0);}
Rust Reference