Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Rounding numbers

by DrHyde (Prior)
on Mar 25, 2014 at 11:23 UTC ( #1079662=note: print w/replies, xml ) Need Help??


in reply to Rounding numbers

As others have mentioned, printf and sprintf are the functions you want:
$ perl -E 'say sprintf("%.2f", 5.5678)' 5.57 $ perl -E 'printf("%.2f\n", 5.5678)' 5.57
If you want to round *all* numbers being written to a file then you may want to write a wrapper around that so you don't have to provide the printf format all the time. One way to do that would be by writing a sub-class of Tie::FileHandle::Base or you could write something based on Tie::STDOUT.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1079662]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2019-07-17 10:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?