jagaranga has asked for the wisdom of the Perl Monks concerning the following question:
Was looking out for the rounding convention used by perl sprintf in-built function.
I was thinking that it does a normal rounding (ROUND_HALF_UP - in Java's rounding mode convention - http://www.j2ee.me/javase/6/docs/api/java/math/RoundingMode.html), but the digging up further proved to be wrong.
>> /usr/local/bin/perl5.10.1 -e 'print(sprintf("%.2f", shift @ARGV)."\n");' 0.335
0.34
>> /usr/local/bin/perl5.10.1 -e 'print(sprintf("%.2f", shift @ARGV)."\n");' 1.335
1.33
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: sprintf rounding convention
by Joost (Canon) on Oct 30, 2009 at 19:22 UTC | |
by ikegami (Patriarch) on Oct 30, 2009 at 22:04 UTC | |
by Joost (Canon) on Oct 30, 2009 at 23:01 UTC | |
by merlyn (Sage) on Oct 31, 2009 at 00:31 UTC | |
by Joost (Canon) on Oct 31, 2009 at 12:33 UTC | |
by kennethk (Abbot) on Oct 30, 2009 at 22:24 UTC | |
by Joost (Canon) on Oct 30, 2009 at 23:14 UTC | |
by ikegami (Patriarch) on Oct 31, 2009 at 01:48 UTC | |
Re: sprintf rounding convention
by Anonymous Monk on Oct 30, 2009 at 19:23 UTC |
Back to
Seekers of Perl Wisdom