[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: convert each element in an array

Logan Capaldo

2/18/2006 6:36:00 PM


On Feb 18, 2006, at 12:53 PM, Jeppe Jakobsen wrote:

> Hi, I can't find out how to convert each integer in my array to a
> float.
> I've tried:
>
> array.each {|x| x.to_f}
>
> But it did not work.
>
> Can anyone tell me the correct method?
>
> --
> "winners never quit, quitters never win"

array.map! { |x| x.to_f } # for in place modification
array2 = array.map { |x| x.to_f } # if you want a new array with
float values without messing up the old array




1 Answer

Jeppe Jakobsen

2/18/2006 8:37:00 PM

0

Thanks!

2006/2/18, Logan Capaldo <logancapaldo@gmail.com>:
>
>
> On Feb 18, 2006, at 12:53 PM, Jeppe Jakobsen wrote:
>
> > Hi, I can't find out how to convert each integer in my array to a
> > float.
> > I've tried:
> >
> > array.each {|x| x.to_f}
> >
> > But it did not work.
> >
> > Can anyone tell me the correct method?
> >
> > --
> > "winners never quit, quitters never win"
>
> array.map! { |x| x.to_f } # for in place modification
> array2 = array.map { |x| x.to_f } # if you want a new array with
> float values without messing up the old array
>
>
>
>


--
"winners never quit, quitters never win"