Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I convert a string to f32?

I'm just started to learn rust and have problem with conversion from string to f32. In nightly 0.11 was function "from_str" and i use it like this:

let f = std::f32::from_str("0.11", 10);

In current 1.0.0 alpha function not exists. How to convert from str to f32 now?

like image 436
Artem Mamonov Avatar asked Jan 30 '15 11:01

Artem Mamonov


1 Answers

you can use parse, now.

let f = "0.11".parse::<f32>(); // returns a Result<f32, std::num::ParseFloatError>`
like image 178
Paolo Falabella Avatar answered Sep 20 '22 22:09

Paolo Falabella