Als Erläuterung paste ich schlicht den relevanten Teil des Kommentars, der nun auch in der Funktion steht:
Trying to round with more precision first only shifts the problem to rarer cases, which nevertheless exist.
Now we exploit the presentation rounding of Perl. Since it really tries hard to recognize integers, we double $amount, and let Perl give us a representation. If Perl recognizes it as a slightly too small integer, and rounds up to the next odd integer, we follow suit and treat the fraction as .5 or greater.
round_amount: Perls Repräsentationsalgorithmus fürs exakte Runden nutzen
Als Erläuterung paste ich schlicht den relevanten Teil des Kommentars,
der nun auch in der Funktion steht:
Trying to round with more precision first only shifts the problem to rarer
cases, which nevertheless exist.
Now we exploit the presentation rounding of Perl. Since it really tries hard
to recognize integers, we double $amount, and let Perl give us a representation.
If Perl recognizes it as a slightly too small integer, and rounds up to the
next odd integer, we follow suit and treat the fraction as .5 or greater.