Edward Edward - 7 months ago 28
Ruby Question

Replacing dot with comma in Ruby spreadsheet

I'm trying to replace the dots with commas in the entire Price-column.

enter image description here

This doesn't work.

#replace dots with commas in price column
@price_column = sheet.column(15)
@price_column.each do |c|
c.to_s.gsub(".",",").to_f
end


What am I doing wrong?

Answer

The issue is that you are using to_f on a string having invalid format for a float. The ruby to_f only take the digits before , and returns the float. You should not be worried about converting the string into float.

The correct code will be:

@price_column = sheet.column(15)
@price_column.each do |c|
   c.to_s.gsub!(/\./,",")
end
Comments