Reputation: 11336
Given this simple Money
object query
Money.new(1000, "USD").to_s
=> "10.00"
How can I display the value with its symbol? I'm aware I can call money_object.symbol
but some currencies place the symbol before and other after the value. Im pretty sure there should be some easy method already for this? Haven't find it by reading into the documentation.
Upvotes: 2
Views: 5705
Reputation: 220
if you are using money-rails
, you have a lots of helpers:
the currency_symbol helper method
<%= currency_symbol %>
This will render a span dom element with the default currency symbol.
the humanized_money helper method
<%= humanized_money @money_object %>
This will render a formatted money value without the currency symbol and without the cents part if it contains only zeros (uses :no_cents_fi_whole flag).
humanize with symbol helper
<%= humanized_money_with_symbol @money_object %>
This will render a formatted money value including the currency symbol and without the cents part if it contains only zeros.
get the money value without the cents part
<%= money_without_cents @money_object %>
This will render a formatted money value without the currency symbol and without the cents part.
get the money value without the cents part and including the currency symbol
<%= money_without_cents_and_with_symbol @money_object %>
This will render a formatted money value including the currency symbol and without the cents part.
Upvotes: 8
Reputation: 14028
ActionView::Helpers::NumberHelper
has number_to_currency
which should do the trick.
Upvotes: 6