method

number_to_delimited

Importance_2
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"
Show source
Register or log in to add new notes.