Version française
Home     About     Download     Resources     Contact us    
Browse thread
What library to use for arbitrary precision decimals
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Joshua Smith <kognate@g...>
Subject: What library to use for arbitrary precision decimals
There are a couple of ways to handle money transactions without
rounding errors.

You could use the Nums library, which provides arbitrary precision
calculations and numbers.   But even with arbitrary precision numbers,
you still can have the situation where you get 405.0345 which if this
were USD, you would still have to round if you wanted to pay someone
this amount.  You will still have the arbitrary precision this way,
however.

The best way to handle money (in my experience) is to use integers. 
Then you can define conversion functions but only have to convert it
to decimal for display purposes.  That way, even if you do a million
transactions you won't lose any information.   You can also handle
non-decimal based currencies/instruments/transactions that way[1]

HTH

-jbs

[1] yes,  there are a (thank god shrinking number) of commodities and
stuff like that in the world that don't use decimal prices.