Wednesday, October 20, 2010

Ruby: Convert numbers to Indian currency format using regex


10000.to_s.gsub(/(\d+?)(?=(\d\d)+(\d)(?!\d))(\.\d+)?/, "\\1,")


Works on decimals too

3 comments:

Sandip Ransing said...

super cool :)

Anonymous said...

you are cool

Piyush said...

ruby is cool :)