primitive-type

Rust f32: 32-bit floating-point number

Use f32 for approximate fractional values when 32-bit precision and storage are appropriate, such as some graphics measurements. It uses binary32 floating-point representation. Expected output: 3.00 Why: The multiplication doubles an exactly representable fraction; the formatting requests two digits after the decimal point. Common mistake: Many decimal fractions cannot be represented exactly.

Formal Syntax & Structure

rust syntaxrust
let name: f32 = floating_literal;

Working Example

Example Snippetrust
fn main() {    let distance: f32 = 1.5;    println!("{:.2}", distance * 2.0);}
Rust Reference