Many times I wanted to round a number in Perl and store it to a variable. Many web pages will teach how to round using printf, but then you can only print the rounded number.
But now, I found this very clever and simple way of rounding numbers in Perl.
It’s interesting to note that there are whole libraries that do the job (Math::Round), but one simple internal Perl function does it too.
$rounded = sprintf “%.1f”, $float;
Thanks to this page.