amount_due = 0.10 + 0.20
amount_paid = 0.30
if amount_paid >= amount_due:
print("PAID")
else:
print("OUTSTANDING")
will print “OUTSTANDING”. amount_due = 0.10 + 0.20
amount_paid = 0.30
if amount_paid >= amount_due:
print("PAID")
else:
print("OUTSTANDING")
will print “OUTSTANDING”.They use binary fixed-point numbers/integers, where such computations are exact, while not having the huge computational overhead of decimal floating-point numbers.
Decimal floating-point is also hardware-supported, so it doesn’t carry the same computational overhead it does on platforms where it must be implemented in software.
IBM has done this, despite it being an inferior technical solution, because it binds those who choose it to IBM hardware.
Programming currency operations with decimal floating-point numbers is easier for naive programmers.
Even on IBM mainframes, implementing currency operations using 64-bit or 128-bit integers is much faster and less resource-consuming than with decimal numbers, but the implementation of some of the operations can be a little tricky, when it must be guaranteed that no loss of precision may occur.
I think that I might have seen recently an announcement from someone else than IBM who has introduced hardware support for decimal floating-point numbers, perhaps from Fujitsu. In any case, whoever introduces such hardware support does it to lure some customers to migrate from IBM to them, and not because it were a good solution for implementing operations with money.
Changing representations isn't a substitute for the numerical analysis you should be doing for financial calcs.