📜  rust u32 to f64 - Rust 代码示例

📅  最后修改于: 2022-03-11 14:49:25.429000             🧑  作者: Mango

代码示例1
//i32:
my_i32 as u32;        // To u32
my_i32.to_string();    // To string
my_i32 as f64;        // To f64

//u32:
my_u32 as i32;        // To i32
my_u32.to_string();    // To string
my_u32 as f64;        // To f64

//f64
my_f64 as i32;        // To i32
my_f64 as u32;        // To u32
my_f64.to_string();    // To string

//String (be mindful of type inference)
my_string.parse().unwrap()        // To i32
my_string.parse().unwrap()        // To u32
my_string.parse().unwrap()        // To f64
// In case the inference is not enough, you can clue rust in by giving it a hint
// example:
my_string.parse::().unwrap();
// But usually that isn't necessary