method

number_to_delimited

Importance_2
number_to_delimited(number, options = {}) public

Formats a number with grouped thousands using delimiter (e.g., 12,324). You can customize the format in the options hash.

Options

  • :locale - Sets the locale to be used for formatting (defaults to current locale).

  • :delimiter - Sets the thousands delimiter (defaults to “,”).

  • :separator - Sets the separator between the fractional and integer digits (defaults to “.”).

Examples

number_to_delimited(12345678)                    # => 12,345,678
number_to_delimited('123456')                    # => 123,456
number_to_delimited(12345678.05)                 # => 12,345,678.05
number_to_delimited(12345678, delimiter: '.')    # => 12.345.678
number_to_delimited(12345678, delimiter: ',')    # => 12,345,678
number_to_delimited(12345678.05, separator: ' ') # => 12,345,678 05
number_to_delimited(12345678.05, locale: :fr)    # => 12 345 678,05
number_to_delimited('112a')                      # => 112a
number_to_delimited(98765432.98, delimiter: ' ', separator: ',')
# => 98 765 432,98
Show source
Register or log in to add new notes.