[Rust] Converting Numbers with as
fn multiply(x: i64, y: u8) -> i64 {
return x * (y as i64);
}
Here we convert u8
to i64
, which is possible since i64
has a wider range than u8
; but you cannot do other way around.
fn divide(x: i32, y: u16) -> f64 {
return x as f64 / y as f64;
}