http://www.perlmonks.org?node_id=1079662


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.