Thread Kaufm. Runden (34 answers)
Opened by mikdoe at 2009-07-06 16:35

hlubenow
 2009-07-08 01:19
#122946 #122946
User since
2009-02-22
875 Artikel
BenutzerIn
[default_avatar]
Doch:
Quote
Rounding in financial applications can have serious implications, and
the rounding method used should be specified precisely. In these
cases, it probably pays not to trust whichever system rounding is being
used by Perl, but to instead implement the rounding function you need
yourself.

To see why, notice how you'll still have an issue on half-way-point
alternation:

for ($i = 0; $i < 1.01; $i += 0.05) { printf "%.1f ",$i}

0.0 0.1 0.1 0.2 0.2 0.2 0.3 0.3 0.4 0.4 0.5 0.5 0.6 0.7 0.7
0.8 0.8 0.9 0.9 1.0 1.0

Don't blame Perl. It's the same as in C. IEEE says we have to do
this. Perl numbers whose absolute values are integers under 2**31 (on
32 bit machines) will work pretty much like mathematical integers.
Other numbers are not guaranteed.

View full thread Kaufm. Runden