1

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)??

legendary_rob
  • 12,792
  • 11
  • 56
  • 102
  • You might want to check what the [I18N Guide](http://guides.rubyonrails.org/i18n.html) has to say. – tadman Dec 07 '11 at 16:18

1 Answers1

3

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

jefflunt
  • 33,527
  • 7
  • 88
  • 126
legendary_rob
  • 12,792
  • 11
  • 56
  • 102