public Method

Kernel.Float(p1)

Float(arg)     float

Returns arg converted to a float. Numeric types are converted directly, the rest are converted using arg.to_f. As of Ruby 1.8, converting nil generates a TypeError.

Float(1)           #=> 1.0
Float("123.456")   #=> 123.456

Source Code

/*
*  call-seq:
*     Float(arg)    => float
*  
*  Returns <i>arg</i> converted to a float. Numeric types are converted
*  directly, the rest are converted using <i>arg</i>.to_f. As of Ruby
*  1.8, converting <code>nil</code> generates a <code>TypeError</code>.
*     
*     Float(1)           #=> 1.0
*     Float("123.456")   #=> 123.456
*/

static VALUE
rb_f_float(obj, arg)
   VALUE obj, arg;
{
   return rb_Float(arg);
}
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.