number_with_delimiter(number, delimiter=",", separator=".") public

Formats a number with grouped thousands using delimiter. You can customize the format using optional delimiter and separator parameters.

  • delimiter - Sets the thousands delimiter, defaults to ","
  • separator - Sets the separator between the units, defaults to "."
 number_with_delimiter(12345678)      => 12,345,678
 number_with_delimiter(12345678.05)   => 12,345,678.05
 number_with_delimiter(12345678, ".")   => 12.345.678
Show source
Register or log in to add new notes.
October 25, 2008
2 thanks

Alternative: use 1000.humanize

1.humanize == “1″ 1000000.humanize == “1.000.000″ 1000.12345.humanize == “1.000,12″

April 9, 2009
0 thanks

Deprecation warning for old-style options

You will get a warning if you don’t define your separators as a hash:

DEPRECATION WARNING: number_with_delimiter takes an option hash instead of separate delimiter and precision arguments

So while you can still use that style, it’s not without a scolding.