architect-handbook

Software Architect Handbook

View on GitHub

Money

Overview

Once you involve multiple currencies you want to avoid adding your dollars to your yen without taking the currency differences into account. The more subtle problem is with rounding. Monetary calculations are often rounded to the smallest currency unit. When you do this it’s easy to lose pennies (or your local equivalent) because of rounding errors.

You can create a Money class that handles those kind of problems.

How It Works

When to Use It

You should use Money for pretty much all numeric calculation in object-oriented environments. You want to encapsulate the handling of rounding behavior, which helps reduce the problems of rounding errors.

Another reason to use Money is to make multi-currency work much easier.