Solved

How to format a number?

Posted on 2001-06-15
1
200 Views
Last Modified: 2010-03-05
I want to format numbers by inserting commas, like 1012345 as 1,012,345 Is there a nice reliable way of doing that?
0
Comment
Question by:Biffo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 5

Accepted Solution

by:
marecs earned 50 total points
ID: 6194150
From the Perl FAQ

perldoc -q "How can I output my numbers with commas added?"

sub commify {                                                  
    local $_  = shift;                                          
    1 while s/^([-+]?\d+)(\d{3})/$1,$2/;                        
    return $_;                                                  
}                                                              

$n = 23659019423.2331;                                          
print "GOT: ", commify($n), "\n";                              
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question