Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Commify numbers

This is just the Ruby version of a known regular expression
to get comma-formatted numbers.


numbers = "10000000 1.345 -91245555.45 +6788876.224334 -2321232" 

numbers.reverse!
numbers.gsub!(/(\d\d\d)(?=\d)(?!\d*\.)/, '\1,')
puts numbers.reverse!


« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS