0

I want to read a float from a csv file: my float is: 0,1660, now I just get the first digit: 0

Here you can see how I am reading it, the float character is in the fourth position of the array row:

CSV.foreach(path, {:col_sep => @seperator}) do |row|

            r = Route.new
            ......
            ....
            r.rate = row [3]

How can I get the whole number? What am I missing? Thanks!

Anna
  • 203
  • 2
  • 7
  • 23

1 Answers1

0

You can write like that "0.1660" not "0,1660". Ruby is not working with decimal number via comma.

[1] pry(main)> 0.111
=> 0.111
[2] pry(main)> 0,111
SyntaxError: unexpected ',', expecting $end
0,111
eayurt
  • 1,169
  • 1
  • 19
  • 42
  • but the problem is that the file I get is already written like this: 0,1660 – Anna Nov 16 '12 at 09:25
  • If you say that the problem is not about comma, problem should be your reading tech. You can check this http://stackoverflow.com/a/4410880/665123 – eayurt Nov 16 '12 at 09:27
  • You can convert the file text on the fly using `row[3].sub(',','.')` – Adrien Coquio Nov 16 '12 at 09:29
  • mm.. problem should be about reading the file, because I just wrote row[3].sub(',','.') and I get this error: undefined method `sub' for nil:NilClass – Anna Nov 16 '12 at 09:36