Kevin Bullock
10/15/2003 6:18:00 PM
In <Pine.LNX.4.53.0310041634120.2132@eli.fsl.noaa.gov> Ara.T.Howard
wrote:
> On Sun, 5 Oct 2003, Meino Christian Cramer wrote:
>> Is there a method/function for "casting" floats to integers ?
>
> Integer(3.14)
There is also a method of Float:
irb(main):008:0> 3.14.to_i
3
>> Something like ( int)(Math.sqrt(2)+1) ???
irb(main):010:0> ((Math.sqrt 2) + 1).to_i
2
Alternatively:
irb(main):011:0> ((Math.sqrt 2) + 1).ceil
3
irb(main):012:0> ((Math.sqrt 2) + 1).floor
2
Depending on what you want out of the float into your integer.