Ano-Tech Computers
Enter keyword:

Converting numbers to two decimal form in Perl
Problem:
How to convert a numeric value to two digit form in Perl? Examples: "12" -- "12.00" "12.3" -- "12.30" "12.34" -- "12.34" "12.345" -- "12.34"
 
Solution:

$formatted = sprintf("%.2f",$unformatted);

(Source: "perldoc -f sprintf")

 
Discuss this solution
Did this article solve your problem? Yes No Did not apply

We welcome anyone who is willing to contribute to this public knowledge base, contact siteadmin@atc.no if you have information you would like to share. The idea is not to replace the commercial support sites, but to publish those hard-to-find solutions you've found yourself looking for over and over again.

Show all articles