Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

by Anonymous Monk
on Apr 04, 2002 at 15:16 UTC ( #156688=note: print w/replies, xml ) Need Help??

in reply to Re: Re: Answer: How do I add commas to a number?
in thread numbers

Then simply extend the search/replace pattern. Since this is just cosmetics, it is not detrimental if it fails. Here is a complete example. Run this code and it will become clear what is going on:
$c1=$c2=$c3=111222333444555; $c1=~ s/^(-?\d+)(\d{3})(\d{3})/$1,$2,$3/; $c2=~ s/^(-?\d+)(\d{3})(\d{3})(\d{3})/$1,$2,$3,$4/; $c3=~ s/^(-?\d+)(\d{3})(\d{3})(\d{3})(\d{3})/$1,$2,$3,$4,$5/; print<<END; $c1 $c2 $c3 END

Replies are listed 'Best First'.
by Biker (Priest) on Apr 04, 2002 at 15:57 UTC

    It doesn't automatically scale. You must write that code with the knowledge of what is the biggest number you will handle.

    "Since this is just cosmetics, it is not detrimental if it fails."

    My users beg to disagree. Numbers not formatted correctly when presented on our Intranet Web pages may have a very high economical impact, including failed trades, penalty fees and loss of reputation.

    The right answer is here.

    A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://156688]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2020-10-01 23:52 GMT
Find Nodes?
    Voting Booth?
    My favourite web site is:

    Results (25 votes). Check out past polls.