From: Peter Date: 2003-12-09T04:37:54+09:00 Subject: Re: format money > Yes, there is. I'm sure that there's a module in the RAA for this, > although I can't find it at the moment. It's not too hard to do manually, > though: > > irb(main):001:0> balance = 2111000.5756 > => 2111000.5756 > irb(main):002:0> balance = (balance * 100).round/100.0 > => 2111000.58 > irb(main):003:0> balance.to_s.reverse.gsub(/\d{3}/, '\&,').reverse > => "2,111,000.58" This would turn 111000.5756 into ,111,000.58 I assume that's not the intention? irb(main):001:0> balance = 111000.5756 => 111000.5756 irb(main):002:0> balance = (balance * 100).round/100.0 => 111000.58 irb(main):003:0> balance.to_s.reverse.gsub(/\d{3}/, '\&,').reverse => ",111,000.58" irb(main):004:0> balance.to_s.reverse.gsub(/\d{3}(?=\d)/, '\&,').reverse => "111,000.58" irb(main):005:0> Peter