From: Jim Van Fleet Date: 2005-02-12T03:04:35+09:00 Subject: Currency formatting with regexp Hi, all, this is my first post to Ruby-talk, so please be kind-- if that's not your natural disposition. I'm looking to work up some code that turns floats into string-based currency values. I've got an implementation working that's pretty ungodly. It looks a lot like I would program it in Java. Naturally, once I finished, I found some Perl suggestion that looks like this: sub commify { my $text = reverse $_[0]; $text =~ s/(\d\d\d)(?=\d)(?!\d*\.)/$1,/g; return scalar reverse $text; } I am a regexp noob. I experimented with using gsub and this regular expression, but I can't seem to get anywhere. The closest I've come replaces the first comma but then eliminates the rest of the number. Can someone help me figure out what's going on-- or point me to where this is already available in Ruby? (Pickaxe II references neither money nor currency, and I don't really want to install extensions just for this functionality.) Thanks so much, Jim