From: James Edward Gray II Date: 2006-02-09T12:47:34+09:00 Subject: Re: Formatting Numbers On Feb 8, 2006, at 7:43 PM, HH wrote: > This has got to be simple but I checked the PickAxe and Google to > no avail. > My guess is that I'm looking for it in terms that don't make sense. > > Anyway... > > I have a fixnum: > > a = 1000 > > I would like to output it with a comma, such as "1,000". Is there a > formatting class or something I can use something along these lines > (thinking from my Java background): > > Formatter f = Formatter.new("N0") > puts f(a) > > Any help appreciated. def commify( str ) str.reverse.gsub(/(\d\d\d)(?=\d)(?!\d*\.)/,'\1,').reverse end Handles floats too. James Edward Gray II