Format currency in Ruby

ActionView::Helpers::NumberHelper:number_to_currency which allows one to format a number according to some options:

  • :precision – Sets the level of precision (defaults to 2).
  • :unit – Sets the denomination of the currency (defaults to "$").
  • :separator – Sets the separator between the units (defaults to ".").
  • :delimiter – Sets the thousands delimiter (defaults to ",").
  • :format – Sets the format of the output string (defaults to "%u%n").

<%=h number_to_currency @transaction.value, :unit => 'R$', :separator => ",", :delimiter => "." %>

[cat Development]

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s