in reply to Re: Rounding problem with sprintf??
in thread Rounding problem with sprintf??

The default behaviour for routines like this is to round down to the nearest number, much like int() does for integers. As a result, rarely does any rounding occur in any Perl or C routines on which Perl is based, such as sprintf.

I don't think this is true, tadman. Testing:

% perl -e 'printf "%1.2f\n", 1.234' 1.23
and
% perl -e 'printf "%1.2f\n", 1.235' 1.24

Which gives me to think that rounding does in principle occur in sprintf and printf. The problem is the floating point representation of base-10 numbers, which occasionally gives you less precision than you though you had. If you really need that precision, hunt around for further discussion on the issue using Super Search, and you'll find plenty.

Update: or just read japhy's response on the original thread.



If God had meant us to fly, he would *never* have give us the railroads.
    --Michael Flanders