Solved

Formatting real numbers for output

Posted on 1997-07-01
1
485 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
[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 51

Accepted Solution

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

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

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying 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

Suggested Solutions

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
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…
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…

752 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