Created
April 10, 2013 19:59
-
-
Save jdittmarCodeSnippets/5357927 to your computer and use it in GitHub Desktop.
Perl: prettyPrintNumber
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# formats floating point numbers so they print nicely | |
sub prettyPrintNumber{ | |
my $number = shift; | |
if(!$number){return "0.00";} | |
$number = ($number < 0.001) ? sprintf('%.2e',$number) : sprintf("%.3f",$number); | |
return $number; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment