Reputation: 4429
I'm using Rails and wanted to convert a float to currency. I'm using number_to_currency
in a Sidekiq Worker, so I've added include ActionView::Helpers::NumberHelper
in the file and where I want the conversion I've added the following:
number_to_currency(value, unit: '', delimeter: '.', separator: ',')
And I wanted the result something like: 1.200,09
but its not working. An example of values I have and want to convert is: 1001.4290000000004
which should be converted to 1.001,43
. I've also tried:
number_to_currency(final_total, unit: '', delimeter: ',', separator: '.')
And still doesn't work. I'm getting is 1,200.09
. I'm using Rails 4.2.x
What am I missing here?
Upvotes: 1
Views: 1460
Reputation: 151
If you want get result like this 1001.4290000000004 => 1,001.43
, you can use this method:
number_with_delimiter(value , delimiter: ",", separator: ".")
But befor u need convert value
to the desired value:
value = 1001.4290000000004.round(2) #=> 1001.43
Upvotes: 2
Reputation: 3080
You just have a typo in word delimiter
. It should be as follows:
number_to_currency(value, unit: '', delimiter: '.', separator: ',')
Upvotes: 1