[Haskell-cafe] money type ?

Robert Daniel Emerson Robert.Emerson at net-tribe.com
Thu Jul 12 09:34:52 EDT 2007


Simon,

I think using Rational is a good solution. I have found tracking multiple 
currencies and commodities problematic. For example take gold, it is traded 
in London in Troy ounces, in Hong Kong in Tael, which is exactly 37.429 
Grams, which differers from the definition of the Main Land Chinese Tael. 
Furthermore they are each bought and sold in different currencies. Since the 
conversion between units and exchange rate is always given to a fixed number 
of digits, I vote for Rational.

Best Regards,
Robert

On Thursday 12 July 2007 15:42, Simon Michael wrote:
> Good day all,
>
> my budding ledger program could not balance transactions exactly because of
> rounding error with Double. I *think* I got it working better with Rational
> (it was late). Another suggestion from #haskell was to multiply all money
> by 100. I'm tracking multiple currencies/commodities with varying precision
> so this gets a bit more complicated.
>
> Is there a type or library out there that's good for representing money and
> other quantities while avoiding rounding errors  ?
>
> Best - Simon
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe


More information about the Haskell-Cafe mailing list