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?
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?
On Feb 18, 2006, at 12:53 PM, Jeppe J. wrote:
–
“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
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs