module ActiveSupport::NumberHelper
def number_to_delimited(number, options = {})
delimiter_pattern: /(\d+?)(?=(\d\d)+(\d)(?!\d))/)
number_to_delimited("123456.78",
# => "98 765 432,98"
number_to_delimited(98765432.98, delimiter: ' ', separator: ',')
number_to_delimited('112a') # => "112a"
number_to_delimited(12345678.05, locale: :fr) # => "12 345 678,05"
number_to_delimited(12345678.05, separator: ' ') # => "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) # => "12,345,678.05"
number_to_delimited('123456') # => "123,456"
number_to_delimited(12345678) # => "12,345,678"
==== Examples
like INR.
deriving the placement of delimiter. Helpful when using currency formats
* :delimiter_pattern - Sets a custom regular expression used for
fractional and integer digits (defaults to ".").
* :separator - Sets the separator between the
to ",").
* :delimiter - Sets the thousands delimiter (defaults
(defaults to current locale).
* :locale - Sets the locale to be used for formatting
==== Options
hash.
(e.g., 12,324). You can customize the format in the +options+
Formats a +number+ with grouped thousands using +delimiter+
def number_to_delimited(number, options = {}) NumberToDelimitedConverter.convert(number, options) end