Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
putting commas in floats to seperate hundreds from thousands etc...
John Kopanas
1/24/2007 6:45:00 PM
I have the following code:
class Float
def to_dollars_with_cents
format("$%.2f", self)
end
end
This way in rails I can go:
@summary.job_cost.to_dollars_with_cents
The output comes out as: $1900000.00
I would prefer to format it as: $1,900,000.00
How would you suggest I do that?
Your Friend,
John
--
John Kopanas
john@kopanas.com
http://www.k...
http://www...
http://www...
2 Answers
Gavin Kistner
1/24/2007 7:02:00 PM
0
On Jan 24, 11:44 am, "John Kopanas" <kopa...@gmail.com> wrote:
> This way in rails I can go:
>
> @summary.job_cost.to_dollars_with_cents
Easier:
http://api.rubyonrails.com/classes/ActionView/Helpers/NumberHelper.ht...
coachhilton
1/24/2007 8:00:00 PM
0
On Jan 24, 11:01 am, "Phrogz" <g...@refinery.com> wrote:
> On Jan 24, 11:44 am, "John Kopanas" <kopa...@gmail.com> wrote:
>
> > This way in rails I can go:
>
> > @summary.job_cost.to_dollars_with_centsEasier:
http://api.rubyonrails.com/classes/ActionView/Helpers/Numbe...
...
The latest edition of Mastering Regular Expressions suggests the
following regex for commafication:
/(\d)(?=(\d\d\d)+(?!\d))/$1,/
Haven't tried look ahead in Ruby but I think this may work for you,
perhaps with some special handling of the "cents" portion of the
amount.
Ken
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
putting commas in floats to seperate hundreds from thousands etc...
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password