Mark J. Reed
10/29/2003 3:44:00 PM
On Wed, Oct 29, 2003 at 03:17:50PM +0000, Robert Cowham wrote:
> Any convenient ways (without rolling my own) of formatting numbers to
> include thousands separators, e.g.
>
> 1199123 printed as "1,199,123"
This should be a FAQ. Does this group have a FAQ? :)
There are library modules that will do this for you, or you can
use the solution from the example in Friedl's book
_Mastering_Regular_Expressions_:
irb(main):001:0> 1199123.to_s.gsub(/(\d)(?=(\d\d\d)+(?!\d))/, '\1,')
=> "1,199,123"
Or any of several variants thereof.
-Mark