Ruby Newbie homepage Ruby Newbie homepage

How to use

Quick guide

Official content
Returns the result of interpreting leading characters in self as a Float:
'3.14159'.to_f  # => 3.14159
'1.234e-2'.to_f # => 0.01234
Characters past a leading valid number (in the given base) are ignored:
'3.14 (pi to two places)'.to_f # => 3.14
Returns zero if there is no leading valid number:
'abcdef'.to_f # => 0.0
 
               static VALUE
rb_str_to_f(VALUE str)
{
    return DBL2NUM(rb_str_to_dbl(str, FALSE));
}
            

Was this page useful?