From: Paul Sutton Date: 2012-05-26T06:11:38+09:00 Subject: Re: max value in an array of csv file --00151748e0ec3f550c04c0e2d0ee Content-Type: text/plain; charset=ISO-8859-1 You are comparing the values as strings ( http://www.ruby-doc.org/core-1.9.3/String.html#method-i-3C-3D-3E). You need to convert the values to floats, by changing p data[0].map {|f| f['price']}.flatten.max to p data[0].map {|f| f['price'].to_f}.flatten.max (although the flatten seems unnecessary). Alternatively: * use the CSV library's numeric converter to convert the fields when they are read * don't use CSV library if the data is this simple --pcs On Fri, May 25, 2012 at 12:06 AM, Ivan Vilches Basaul < ivan_vilches@hotmail.com> wrote: > anyone can give me a hand with this pls > http://pastie.org/3964924 > --00151748e0ec3f550c04c0e2d0ee Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable You are comparing the values as strings (http://www.ruby-doc.org/core-1.9= .3/String.html#method-i-3C-3D-3E). You need to convert the values to fl= oats, by changing
p data[0].map {|f| f['price']}.flatten.max
to
p=
 data[0].map {|f| f['price'].to_f}.f=
latten.max
(although the flatten seems unnecessary).

Alternatively:

* u= se the CSV library's numeric converter to convert the fields when they = are read
* don't use CSV library if the data is this simple

--pcs

On Fri, May 25, 2012 at 12:06 A= M, Ivan Vilches Basaul <ivan_vilches@hotmail.com> wro= te:
anyone can give me a hand with this pls
http://pastie.org/3964924

--00151748e0ec3f550c04c0e2d0ee--