This language bar is your friend. Select your favorite languages!

Idiom #146 Convert string to floating point number

Extract floating point value f from its string representation s

let f = s.parse::<f32>().unwrap();
import std.conv;
float f = s.to!float;
f = num.parse(s);
import "strconv"
f, err := strconv.ParseFloat(s, 64)
read s :: Double
$f = floatval($s);
uses sysutils;
f := s.ToExtended;
sysutils
f := StrToFloat(s);
import locale
s = u'545,2222'
locale.setlocale(locale.LC_ALL, 'de')
f = locale.atof(s)
f = float(s)
f = s.to_f

Do you know the best way to do this in your language ?
New implementation...

Idiom created by

programming-idioms.org

Related idioms