number_with_delimiter
![Wide documentation Importance_3](https://d2vfyqvduarcvs.cloudfront.net/images/importance_3.png?1349367920)
- 1.0.0 (0)
- 1.1.6 (0)
- 1.2.6 (12)
- 2.0.3 (4)
- 2.1.0 (0)
- 2.2.1 (13)
- 2.3.8 (0)
- 3.0.0 (-4)
- 3.0.9 (-1)
- 3.1.0 (0)
- 3.2.1 (12)
- 3.2.8 (0)
- 3.2.13 (0)
- 4.0.2 (0)
- 4.1.8 (0)
- 4.2.1 (0)
- 4.2.7 (0)
- 4.2.9 (0)
- 5.0.0.1 (0)
- 5.1.7 (8)
- 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 (-38)
- 7.1.3.4 (0)
- What's this?
number_with_delimiter(number, *args)
public
Formats a number with grouped thousands using delimiter (e.g., 12,324). You can customize the format in the options hash.
Options
- :delimiter - Sets the thousands delimiter (defaults to ",").
- :separator - Sets the separator between the units (defaults to ".").
Examples
number_with_delimiter(12345678) # => 12,345,678 number_with_delimiter(12345678.05) # => 12,345,678.05 number_with_delimiter(12345678, :delimiter => ".") # => 12.345.678 number_with_delimiter(12345678, :separator => ",") # => 12,345,678 number_with_delimiter(98765432.98, :delimiter => " ", :separator => ",") # => 98 765 432,98
You can still use number_with_delimiter with the old API that accepts the delimiter as its optional second and the separator as its optional third parameter:
number_with_delimiter(12345678, " ") # => 12 345.678 number_with_delimiter(12345678.05, ".", ",") # => 12.345.678,05
![Default_avatar_30](https://www.gravatar.com/avatar/59436ecd4fe6ad7c34f67654d839f05f?default=http://apidock.com/images/default_avatar_30.png&size=30)
Alternative: use 1000.humanize
1.humanize == “1″ 1000000.humanize == “1.000.000″ 1000.12345.humanize == “1.000,12″
http://pragmatig.wordpress.com/2008/10/25/numbers-for-humans-humanize-for-numeric/
![Default_avatar_30](https://www.gravatar.com/avatar/b850a6cd0c0f8993fa152645ca9a7fbd?default=http://apidock.com/images/default_avatar_30.png&size=30)
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.