Just a reminder
Showing posts with label
format
.
Show all posts
Showing posts with label
format
.
Show all posts
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
Older Posts
Home
Subscribe to:
Posts (Atom)
Blog Archive
▼
2009
(29)
▼
October
(1)
DataMapper - migration from 0.9.x to 0.10.x
►
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)
►
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