in reply to Re: sprintf and decimals
in thread sprintf and decimals

thanks. So that'll be why this bit of code returns the following
#!/usr/bin/perl $w=2.315; $x=2.3150141; $y=sprintf("%.2f", $w); $z=sprintf("%.2f", $x); print "$w rounded is $y\n"; print "$x rounded is $z\n";
2.315 rounded is 2.31
2.3150141 rounded is 2.32

Replies are listed 'Best First'.
Re^3: sprintf and decimals
by ikegami (Patriarch) on Nov 15, 2006 at 18:55 UTC

    oh! I didn't know it looks at more than the next digit.

    To continue the example in my previous post, that means
    5.1 > 5, so 2.6751 rounds to 2.68