Solved

Formatting real numbers for output

Posted on 1997-07-01
1
463 Views
Last Modified: 2012-08-14
This should be a piece of cake to all you die-hard Perl spods out there, but I don't have the time to trawl through the net and find what I need, and I don't have any printed Perl literature that I can consult. Learning a language by hacking other peoples' code is fine as far as it goes, but only if they've ever done what you need to do yourself...

How do I do decimal formatting on real (ie. not integer) numbers in Perl? Basicallly I have a variable which will contain something like 7.333333333333 and I only want to print the first couple of digits after the decimal point.
0
Comment
Question by:loccy
1 Comment
 
LVL 51

Accepted Solution

by:
ahoffmann earned 50 total points
ID: 1204540
something like:

      printf("%5.3g", $your_val);

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
perl to display a matrix report for 3-dimenional array 3 64
Perl script to parse xml file 2 104
stftime format 4 55
XPath Syntax help in conjunction with perl XML::LibXML 18 104
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
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…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

863 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now