Solved

Formatting real numbers for output

Posted on 1997-07-01
1
447 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

707 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

13 Experts available now in Live!

Get 1:1 Help Now