Subject: | Error in round() |
In Number::Format v1.51 the round() function adds on .50000001 which is
incorrect. If, for example you were to format the number
-8748371.49999999 to zero d.p. you get -8748372 which is wrong. I guess
that the 1 digit is added because of the inability to accurately store
certain numbers but these errors are generally of order +-(1E-14).
Therefore if this digit must be used at all it should be placed further
down at the 14th place.
Example...
perl -e 'my $x=0; for (1..55) { $x += 0.1; } print "$x\n"; print $x-5.5
. "\n";'
yields
5.5
-3.5527136788005e-15
rounding under your current code to 0 d.p. would correctly give 6
whereas without the digit 5 would result. However placing the digit in
the 14th place also gives the correct result and has less chance of
affecting other results.
Maybe having a default of no digit and an option to set it's position
otherwise?