Method: ActiveSupport::NumberHelper#number_to_percentage
- Defined in:
- activesupport/lib/active_support/number_helper.rb
#number_to_percentage(number, options = {}) ⇒ Object
Formats number as a percentage string.
number_to_percentage(100) # => "100.000%"
number_to_percentage("99") # => "99.000%"
number_to_percentage("99x") # => "99x%"
number_to_percentage(12345.6789, delimiter: ".", separator: ",", precision: 2)
# => "12.345,68%"
Options
:locale-
The locale to use for formatting. Defaults to the current locale.
number_to_percentage(1000, locale: :fr) # => "1000,000%" :precision-
The level of precision, or
nilto preservenumber‘s precision. Defaults to 2.number_to_percentage(12.3456789, precision: 4) # => "12.3457%" number_to_percentage(99.999, precision: 0) # => "100%" number_to_percentage(99.999, precision: nil) # => "99.999%" :round_mode-
Specifies how rounding is performed. See
BigDecimal.mode. Defaults to:default.number_to_percentage(12.3456789, precision: 4, round_mode: :down) # => "12.3456%" :significant-
Whether
:precisionshould be applied to significant digits instead of fractional digits. Defaults to false.number_to_percentage(12345.6789) # => "12345.679%" number_to_percentage(12345.6789, significant: true) # => "12300%" number_to_percentage(12345.6789, precision: 2) # => "12345.68%" number_to_percentage(12345.6789, precision: 2, significant: true) # => "12000%" :separator-
The decimal separator. Defaults to
".". :delimiter-
The thousands delimiter. Defaults to
",". :strip_insignificant_zeros-
Whether to remove insignificant zeros after the decimal separator. Defaults to false.
:format-
The format of the output.
%nrepresents the number. Defaults to"%n%".number_to_percentage(100, format: "%n %") # => "100.000 %"
223 224 225 |
# File 'activesupport/lib/active_support/number_helper.rb', line 223 def number_to_percentage(number, = {}) NumberToPercentageConverter.convert(number, ) end |