[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Number formatting?

Robert Cowham

10/29/2003 3:18:00 PM

Any convenient ways (without rolling my own) of formatting numbers to
include thousands separators, e.g.

1199123 printed as "1,199,123"


--
Robert Cowham

5 Answers

Mark J. Reed

10/29/2003 3:44:00 PM

0

On Wed, Oct 29, 2003 at 03:17:50PM +0000, Robert Cowham wrote:
> Any convenient ways (without rolling my own) of formatting numbers to
> include thousands separators, e.g.
>
> 1199123 printed as "1,199,123"


This should be a FAQ. Does this group have a FAQ? :)

There are library modules that will do this for you, or you can
use the solution from the example in Friedl's book
_Mastering_Regular_Expressions_:

irb(main):001:0> 1199123.to_s.gsub(/(\d)(?=(\d\d\d)+(?!\d))/, '\1,')
=> "1,199,123"

Or any of several variants thereof.

-Mark

Simon Strandgaard

10/29/2003 5:58:00 PM

0

On Wed, 29 Oct 2003 15:44:09 +0000, Mark J. Reed wrote:

> On Wed, Oct 29, 2003 at 03:17:50PM +0000, Robert Cowham wrote:
>> Any convenient ways (without rolling my own) of formatting numbers to
>> include thousands separators, e.g.
>>
>> 1199123 printed as "1,199,123"
>
>




There is many variants located here:
http://www.rubygarden.org/ruby?Fi...

--
Simon Strandgaard

Robert Cowham

10/29/2003 11:35:00 PM

0

Simon Strandgaard <qj5nd7l02@sneakemail.com> wrote in
news:pan.2003.10.29.17.58.22.60481@sneakemail.com:

> http://www.rubygarden.org/ruby?Fi...

Thanks - just what I was looking for!

--
Robert Cowham

gsinclair

10/30/2003 4:37:00 AM

0

Robert Cowham <rc@vaccaperna.co.uk> wrote in message news:<Xns9423EF9E093CCrcvaccapernacouk@130.133.1.4>...
> Simon Strandgaard <qj5nd7l02@sneakemail.com> wrote in
> news:pan.2003.10.29.17.58.22.60481@sneakemail.com:
>
> > http://www.rubygarden.org/ruby?Fi...
>
> Thanks - just what I was looking for!

I included a modified version of Austin's excellent solution in
http://extensions.rub....

Gavin

Jesus Christ the Holy Cunt Fucker

12/25/2008 10:04:00 AM

0

Chinese shall definitely have modern air- crafts
even though Chinese can make the engine AL 31 ,




Dec 25, 4:57 pm, Jesus Christ the Holy Cunt Fucker
<veak...@gmail.com> wrote:
> Chinese  are  preparing  to  make the  naval  version  of the  Sukhoi
> 27  and  31  models .
>
> Russian  are  preparing  for the Chinese  naval  air crafts
> industries .
>
> the  problem  is the  magnetic  catapult  system which
> the German are  developing , will  German sell  the  electro-
> Magnetic  catapult
>  system to China .?
>
> It  depends  on  the  treatment  of  the  Uyghurs  by the  Chinese .
>
> because the  Adenaur Foundation  is  funding  the  money
> to  support  the  Uyghur  movemment  in Xin  Jiang .
>
>  Dec 25, 11:49 am, residualselfimage1...@gmail.com wrote:
>
> > On Dec 24, 8:47 am, Amelita <clitte...@yahoo.com> wrote:
>
> > > The Washington Post
> > > Wednesday, December 24, 2008; A08
>
> > > CHINA
>
> > > "Government May Build Its First Aircraft Carrier"
>
> > > China will "seriously consider" building its first aircraft carrier,
> > > the Defense Ministry said Tuesday, in another sign of Beijing's
> > > expanding military ambitions.
>
> > > An aircraft carrier is "a symbol of a country's overall national
> > > strength as well as the competitiveness of the country's naval force,"
> > > a ministry spokesman said. He said China must ensure its maritime
> > > security and sovereignty but gave no timetable for launching such a
> > > vessel.
>
> > > China's navy usually stays close to its shores, though the government
> > > said Tuesday it will send three ships to the Indian Ocean to deter
> > > pirate attacks on Chinese vessels.
>
> > > China's neighbors have been watching closely as the country's defense
> > > spending has grown at double-digit rates in recent years.
>
> > >http://www.washingtonpost.com/wp-dyn/content/article/2008/1.......
>
> > An aircraft carrier needs several escort ships to protect it.
> > So one doesn't really plan for an aircraft carrier but an
> > aircraft carrier fleet - a very expensive proposition.
> > The problem with containing the pirates off the coast
> > of Somali is cost  - who is going to pay for the policing
> > action and how is it going to work out? In my humble
> > opinion - the shipping insurance/underwriters should
> > pay for atleast some of the cost of martine policing,
> > .