method
number_to_delimited
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 (38)
- 5.1.7 (0)
- 5.2.3 (0)
- 6.0.0 (0)
- 6.1.3.1 (0)
- 6.1.7.7 (0)
- 7.0.0 (0)
- 7.1.3.2 (-37)
- 7.1.3.4 (0)
- What's this?
number_to_delimited(number, options = {})
public
Formats number by grouping thousands with a delimiter.
number_to_delimited(12345678) # => "12,345,678" number_to_delimited("123456") # => "123,456" number_to_delimited(12345678.9876) # => "12,345,678.9876" number_to_delimited("12x34") # => "12x34" number_to_delimited(12345678.9876, delimiter: ".", separator: ",") # => "12.345.678,9876"
Options
- :locale
-
The locale to use for formatting. Defaults to the current locale.
number_to_delimited(12345678.05, locale: :fr) # => "12 345 678,05"
- :delimiter
-
The thousands delimiter. Defaults to ",".
number_to_delimited(12345678, delimiter: ".") # => "12.345.678"
- :separator
-
The decimal separator. Defaults to ".".
number_to_delimited(12345678.05, separator: " ") # => "12,345,678 05"
- :delimiter_pattern
-
A regexp to determine the placement of delimiters. Helpful when using currency formats like INR.
number_to_delimited("123456.78", delimiter_pattern: /(\d+?)(?=(\d\d)+(\d)(?!\d))/) # => "1,23,456.78"