- or download this
sub round($$)
{
sprintf "%.$_[1]f",$_[0];
}
print round(8.7385, 2); # prints 8.74
- or download this
for my $i (0 .. 10)
{
print round($i+0.555,2)," ";
}
# which prints:
# 0.56 1.56 2.56 3.56 4.55 5.55 6.55 7.55 8.55 9.55 10.56
- or download this
for (my $i = 1; $i < \xFFFF; $i <<= 1)
{ print round($i+0.555,2), " "; }
# which prints:
...
#
#(You can try with different numbers and different precision as long
# as the last digit is '5' and the precision = number of digits - 1)
- or download this
sub round2($$)
{
my $var=$_[0];
...
# some output:
for (my $i = 1; $i < \xFFFF; $i <<= 1)
{ print round($i+0.555,2), " ", round2($i+0.555,2), "\n"; }