I can't find out how to parse a float from current Rust, according to the documentation I think this should work :
use std::f32;
use std::from_str::FromStr;
fn main() {
let result = f32::from_str("3.14");
println!("{}", result.unwrap());
}
but the compiler complains :
<anon>:5:18: 5:31 error: unresolved name `f32::from_str`.
<anon>:5 let result = f32::from_str("3.14");
^~~~~~~~~~~~~
(See on Rust playpen : here)
What I am missing here ?
In 1.0.0 alpha~Nightly you can use std::str::StrExt::parse instead
assert_eq!("3.14".parse(), Ok(3.14f64))
Also here's a sample with your code
fn main() {
let result: f32 = "3.14".parse().unwrap();
println!("{}", result);
}
Playpen link
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With