Mark Hubbart
2/12/2005 12:33:00 AM
On Sat, 12 Feb 2005 03:25:20 +0900, James Edward Gray II
<james@grayproductions.net> wrote:
> On Feb 11, 2005, at 12:04 PM, Jim Van Fleet wrote:
>
> > sub commify {
> > my $text = reverse $_[0];
> > $text =~ s/(\d\d\d)(?=\d)(?!\d*\.)/$1,/g;
> > return scalar reverse $text;
> > }
>
> Here's a direct Ruby translation:
>
> def commify( number )
> text = number.to_s.reverse
> text.gsub!(/(\d\d\d)(?=\d)(?!\d*\.)/, '\1,')
> text.reverse
> end
golf?
def commify(num)
num.to_s.reverse.scan(/..?.?/).join(",").reverse
end
... sorry, couldn't resist. Weak character.
cheers,
Mark