lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Sun, Sep 04, 2016 at 09:20:13PM -0300, Diogo Mildenberger wrote:
> Hello!
> 
> Has someone any experience to share about implementing a system that deals
> with currency values? I have already been bitten by the problems described
> in http://floating-point-gui.de/ and I want to find a better way.
> 
> It is mentioned in that guide and elsewhere about using fixed-point
> arithmetic (https://en.wikipedia.org/wiki/Fixed-point_arithmetic even
> mentions GnuCash took the same route), and from what I read, it is
> implemented using scaled integers, pretty much. Is that it? Has anyone some
> insights?

Another thing that is important to remember: Not all currencies are
decimal, and actually most currencies are /centimal/.

There exist currencies where the subdivision is not 100: 10 and 1000
exist.  Then there are currencies with no subdivision at all, such as
Yen.

When handling money calculations, you basically have to go and read the
Wikipedia article for every currency you're ever likely to handle so you
can manage all the hideous corner cases.

B.