Why and how does this line work:
let guess: f64 = "42".parse().expect("Not a number!");
But is that not so?
let guess: i32 = "42.0".parse().expect("Not a number!");
Result:
thread 'main' panicked at 'Not a number!: ParseIntError { kind: InvalidDigit }'
What is the correct way to parse "float" & str to an integer?
Update:
I found this to work:
let guess: i32 = "42.0".parse::<f64>().expect("Not a number!") as i32;
However, I do not understand the mechanics of how this works, and if this is the right way to do this?
source
share