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
float fl = std::stof("1.5");
var f=float.Parse(s);
import std.conv;
float f = s.to!float;
f = num.parse(s);
read (unit=s,fmt=*) f
read(s,'(g0)')f
import "strconv"
f, err := strconv.ParseFloat(s, 64)
read s :: Double
String floatString = "14.5";
float x = Float.parseFloat(floatString);
double y = Double.parseFloat(floatString);
$f = floatval($s);
sysutils
f := StrToFloat(s);
uses sysutils;
f := s.ToExtended;
my $f = $s;
f = float(s)
import locale
s = u'545,2222'
locale.setlocale(locale.LC_ALL, 'de')
f = locale.atof(s)
float("1.3")
f = s.to_f
let f = s.parse::<f32>().unwrap();

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

Idiom created by

programming-idioms.org

Related idioms