[Haskell-cafe] What is a safe Haskell data type to store and manipulate Money values?

Richard A. O'Keefe ok at cs.otago.ac.nz
Thu Apr 6 22:35:13 UTC 2017

> On 6/04/2017, at 6:32 PM, David Turner <dct25-561bs at mythic-beasts.com> wrote:
> Careful here. I've worked on systems where one of the fundamental requirements is that any sums of columns of numbers representing amounts of money _must_ add up precisely. In a situation where you apply different tax rates to different items you could either calculate the tax on each one (and round it to £0.01) or group the items together into subtotals that all had the same tax rate, then calculate the tax on the subtotal (and round it to £0.01). What you couldn't do was keep track of the precise amount of tax on each item and round it at the very end for reporting purposes only, because you had to show the tax breakdown (using numbers rounded to £0.01) and if your working calculation was more precise then the numbers in the report wouldn't always quite add up, which would upset the auditors.

For what it's worth, there are rounding algorithms that work on a whole bunch of numbers
at once, ensuring that the total of the rounded numbers is equal to the total of the
unrounded numbers.

More information about the Haskell-Cafe mailing list