number_to_percentage
- 1.0.0
- 1.1.6
- 1.2.6
- 2.0.3
- 2.1.0
- 2.2.1
- 2.3.8
- 3.0.0
- 3.0.9
- 3.1.0
- 3.2.1
- 3.2.8
- 3.2.13
- 4.0.2 (0)
- 4.1.8 (0)
- 4.2.1 (0)
- 4.2.7 (0)
- 4.2.9 (0)
- 5.0.0.1 (17)
- 5.1.7 (0)
- 5.2.3 (0)
- 6.0.0 (0)
- 6.1.3.1 (38)
- 6.1.7.7 (0)
- 7.0.0 (0)
- 7.1.3.2 (-12)
- 7.1.3.4 (0)
- What's this?
number_to_percentage(number, options = {})
public
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 nil to preserve number'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 :precision should 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. %n represents the number. Defaults to "%n%".
number_to_percentage(100, format: "%n %") # => "100.000 %"