Logo

Programming-Idioms

History of Idiom 146 > diff from v23 to v25

Edit summary for version 25 by daxim:
New Perl implementation by user [daxim]

Version 23

2019-09-26, 14:27:21

Version 25

2019-09-27, 08:10:13

Idiom #146 Convert string to floating point number

Extract floating point value f from its string representation s

Idiom #146 Convert string to floating point number

Extract floating point value f from its string representation s

Extra Keywords
real conversion
Extra Keywords
real conversion
Code
my $f = $s;
Doc URL
http://modernperlbooks.com/books/modern_perl_2016/03-perl-language.html#VmFyaWFibGVzLFR5cGVzLGFuZENvZXJjaW9u
Code
String floatString = "14.5";
float x = Float.parseFloat(floatString);
double y = Double.parseFloat(floatString);
Comments bubble
Will throw NullPointerException if floatString is null or NumberFormatException if the string is not actually a float.