ActionView::Helpers::NumberHelper

number_to_percentage

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

Description

Formats the number as a percentage string.

Arguments

Changing a value updates the ERB and HTML.

Converts the number to a string using ActiveSupport::NumberHelper. A non-numeric value ("abc") is inserted into the format unchanged instead of raising an error. Returns nil for nil.
options= {}
"%n %"
The format, where %n is replaced with the number. The given string is escaped.
true raises InvalidNumberError when the number argument is not a number.

Rounding options

1
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.
How to round: :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 used for the decimal point. It is escaped.
"."
The string inserted every three digits. It 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.percentage.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