method
number_to_rounded
Ruby on Rails latest stable (v7.1.3.2)
-
0 notes -
Class: NumberHelper
- 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 (18)
- 5.1.7 (0)
- 5.2.3 (0)
- 6.0.0 (0)
- 6.1.3.1 (23)
- 6.1.7.7 (0)
- 7.0.0 (0)
- 7.1.3.2 (-38)
- 7.1.3.4 (0)
- What's this?
number_to_rounded(number, options = {})
public
Formats number to a specific level of precision.
number_to_rounded(12345.6789) # => "12345.679" number_to_rounded(12345.6789, precision: 2) # => "12345.68" number_to_rounded(12345.6789, precision: 0) # => "12345" number_to_rounded(12345, precision: 5) # => "12345.00000"
Options
- :locale
-
The locale to use for formatting. Defaults to the current locale.
number_to_rounded(111.234, locale: :fr) # => "111,234"
- :precision
-
The level of precision, or nil to preserve number's precision. Defaults to 3.
number_to_rounded(12345.6789, precision: nil) # => "12345.6789"
- :round_mode
-
Specifies how rounding is performed. See BigDecimal.mode. Defaults to :default.
number_to_rounded(12.34, precision: 0, round_mode: :up) # => "13"
- :significant
-
Whether :precision should be applied to significant digits instead of fractional digits. Defaults to false.
number_to_rounded(12345.6789) # => "12345.679" number_to_rounded(12345.6789, significant: true) # => "12300" number_to_rounded(12345.6789, precision: 2) # => "12345.68" number_to_rounded(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.
number_to_rounded(12.34, strip_insignificant_zeros: false) # => "12.340" number_to_rounded(12.34, strip_insignificant_zeros: true) # => "12.34" number_to_rounded(12.3456, strip_insignificant_zeros: true) # => "12.346"