in reply to Re^4: Behaviour of int() unexpected
in thread Behaviour of int() unexpected
Financial data, like banks, tax authorities, etc have fixed rules about precision and rounding to avoid ambiguity. And these date back to integer times.
You can just calculate in integer if you use cents or the required fractions of them and respect the rounding rules.
IOW instead of calculating with a float 5,02€ you calculate with 502¢ or 5020 deci-cents.
You only need to "shift" the point once you're putting out the result (best string wise)
I haven't seen a case yet where this didn't work.
Cheers Rolf
(addicted to the Perl Programming Language :)
see Wikisyntax for the Monastery
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: Behaviour of int() unexpected
by cavac (Prior) on Mar 14, 2025 at 07:36 UTC |