Skip to content

Instantly share code, notes, and snippets.

@jdittmarCodeSnippets
Created April 10, 2013 19:59
Show Gist options
  • Save jdittmarCodeSnippets/5357927 to your computer and use it in GitHub Desktop.
Save jdittmarCodeSnippets/5357927 to your computer and use it in GitHub Desktop.
Perl: prettyPrintNumber
# 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