Just a reminder
Sep 18, 2008
[RUBY] Formating numbers with commas
I want to format the numbers with commas, there maybe a better way to do it, but this one works for me:
# Return String formated as "123,456.78"
def format_number(number)
s = "%0.2f" % number
s =~ /([^\.]*)(\..*)?/
int, dec = $1, $2
int.gsub(/(\d)(?=\d{3}+(\.\d*)?$)/, '\1,') + dec
end
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
Blog Archive
►
2009
(29)
►
October
(1)
►
September
(1)
►
August
(4)
►
July
(2)
►
June
(2)
►
May
(2)
►
April
(4)
►
March
(4)
►
February
(5)
►
January
(4)
▼
2008
(18)
►
December
(4)
►
November
(3)
►
October
(1)
▼
September
(2)
Step by step setting up an OS X Leopard server for...
[RUBY] Formating numbers with commas
►
August
(5)
►
July
(3)
Labels
_why
Ack
Automator
autotest
baby
bluetooth
c++
compile
ctags
datamapper
daycare
Elaine
flot
fonts
format
FOWA
git
GMail
iPhone
javascript
Mac
MacBook Pro
MaxDB
Merb
Merb authorization
merb routes
Migration
MySQL
new born
new year
new_born
OS X
pdf
performance
Phusion Passenger
Prawn
prefpane
quartz
Rack
Rails
render
ruby
SapDB
sleep
SSL
target
TinkerTool
tuning
video
Vim
About Me
zhhz
Newark, Delaware, United States
View my complete profile
No comments:
Post a Comment