In a rails 5.2.0 and ruby 2.5.1 project I'm generating CSV files where there are a lot of decimal numbers, formatting them with number_to_rounded and using comma as decimal separator:
irb(main):006:0> number_to_rounded(tot_calculation, precision: 2, separator: ',')
=> "0,37"
irb(main):214:0> rows << [ number_to_rounded(p.import, precision: 2, separator: ','), number_to_rounded(p.last_value, precision: 2, separator: ','),number_to_rounded(p.percentage, precision: 2, separator: ',')]
=> [["110000,00", "110000,00", "0,46"]]
When exporting csv with
csv_data = CSV.generate(headers: true, col_sep: ';') do |csv|
csv << headers
rows.each { |row| csv << row }
end
data_csv.attach(io: StringIO.new(csv_data), filename: "#{Date.today.strftime("%Y%m%d")}_daily.csv", content_type: 'text/csv')
decimal separator used is dot instead of comma. I checked locale and it is :it as it should be.
csv_data is: ".......on\n110000,00;110000,00;0,46\n"
The plaintext of generated file is using dots: 0.00;943.84;943.84;90.00;100.00;117000.00;117000.00;
How can I make generated CSV using comma as decimal separator?

:itin this case.csv << ['0,00', '943,84']. Of course, you can usenumber_to_roundedto format them.