10. Decimal, Money, and Other Classes

In the movie Superman III, a computer genius figures out that if he can steal fractions of a penny in each transaction done by a bank, transferring that fraction to his own account, he can enrich himself. That’s because a fraction of a penny multiplied by millions of transactions a day adds up to a fortune.

That’s why bankers care about rounding errors. They’re aware that fractions of a penny can add up. Precise amounts matter.

Early on, electronic computers were used for commercial purposes, making it important to record dollars and cents (or any currency) precisely, without errors. That’s what this chapter is all about: utilizing ways of tracking data especially suited for financial purposes. This chapter ...

Get Supercharged Python: Take Your Code to the Next Level, First Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.