Divide integers and get float
- as
- f32
fn main() { let x = 8; let y = 3; let div = x / y; println!("{x} / {y} = {div}"); // 8 / 3 = 2 let div = x as f32 / y as f32; println!("{x} / {y} = {div}"); // 8 / 3 = 2.6666667 }
8 / 3 = 2
8 / 3 = 2.6666667
Press ← or → to navigate between chapters
Press S or / to search in the book
Press ? to show this help
Press Esc to hide this help
fn main() { let x = 8; let y = 3; let div = x / y; println!("{x} / {y} = {div}"); // 8 / 3 = 2 let div = x as f32 / y as f32; println!("{x} / {y} = {div}"); // 8 / 3 = 2.6666667 }
8 / 3 = 2
8 / 3 = 2.6666667