ActionView::Helpers::NumberHelper

number_to_currency

API docs (Rails 8.1.4.1) ↗
def number_to_currency(number, options = {})

Description

Formats the number as a currency string.

Arguments

Changing a value updates the ERB and HTML.

Converts the number to a string using ActiveSupport::NumberHelper. The format comes from Rails' built-in English translations (number.currency, etc.). A non-numeric value ("abc") is inserted into the format unchanged instead of raising an error. Returns nil for nil.
options= {}
"円"
Uses the given string as the unit instead of $. The unit is escaped.
"%n%u"
The format, where %u is replaced with the unit and %n with the number. The given string is escaped.
"(%u%n)"
The format for negative numbers. Defaults to the :format option prefixed with -. The given string is escaped. Not used for a negative number that rounds to 0.
true raises InvalidNumberError when the number argument is not a number.

Rounding options

0
The number of digits after the decimal point, or the number of significant digits when the :significant option is true.
true treats precision as the number of significant digits. false treats it as the number of digits after the decimal point. When precision is 0, rounds to an integer even if this is true.
true removes trailing 0 digits after the decimal point.
The rounding mode. :down rounds toward zero and :up rounds away from zero. Defaults to rounding half up. Other BigDecimal rounding modes (:half_even, :half_down, :ceiling, :floor, etc.) also work.
","
The string to use as the decimal separator. The given string is escaped.
"."
The string to use as the thousands delimiter. The given string is escaped.
Every NumberHelper helper handles the rounding options the same way (ActiveSupport::NumberHelper's NumberToRoundedConverter). Their defaults differ from helper to helper.Options not listed here do not become HTML attributes. With :locale, uses that language's number format translations (number.currency.format, etc.). This site provides no number format translations, so :ja gets Rails' built-in English format (a language this site does not have raises I18n::InvalidLocale).

ERB

Changes from the previous output: Added Removed Changed


          

HTML