[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

How to format a number?

Posted on 2001-06-15
1
Medium Priority
?
210 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 200 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
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…
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

650 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