operator

Rust /: integer and floating-point division

Integer division discards the fractional part toward zero. Floating-point division retains fractions when representable. Integer division by zero panics. Expected output (not executed): 1 1.58 -2 Why: The integer result counts complete hours, the floating-point result approximates hours, and negative division truncates toward zero. Common mistake: Converting the result after integer division cannot recover the discarded fraction. Also handle MIN / -1 for signed integers. Advanced connection: `std::ops::Div`; `DivAssign` for `/=`.

Formal Syntax & Structure

rust syntaxrust
a / b

Working Example

Example Snippetrust
fn main() {    let minutes = 95;    println!("{}", minutes / 60);    println!("{:.2}", minutes as f64 / 60.0);    println!("{}", -7 / 3);}
Rust Reference