Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Formatting real numbers for output

Posted on 1997-07-01
1
Medium Priority
?
501 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 200 total points
ID: 1204540
something like:

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

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

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…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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

885 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