Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Rounding numbers

by DrHyde (Prior)
on Mar 25, 2014 at 11:23 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1079662]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2024-04-25 22:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found