Reputation: 13012
Hi i am messing around with rails, there is a method built into rails that can convert a decimal number into a currency. I could just change it in the view but i would like to internalize it into the application so that i can save on the maintenance.
<span class="price"><%= product.price %></span>
In my index template i have this and could change it to american dollars just like this:
<span class="price"><%= number_to_currency(product.price) %></span>
I did find several was of changing it into euro's the rails API is great:
number_to_currency(1234567890.506, :locale => :fr) #this will change it euros/france
Now does anyone know where i could get a list for all the different areas? and there currencies? in particular South Africa(ZAR)??
Upvotes: 1
Views: 2144
Reputation: 13012
To change the currency you just have to specify it like this:
<span class="price"><%= number_to_currency(product.price, :unit => "R") %></span>
Then to make it cohesive, you would have to write a short math sum to preform the conversions, and just have a file update with the daily exchange rates that are then loaded into the sum.
I should have researched this a little more thanks for the comments
Upvotes: 3