lua-users home
lua-l archive

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


On Mon, 14 Apr 2008 19:38:56 +0200, Aladdin Lampé
<genio570@hotmail.fr> wrote:

>
>Hi Lua list!
>
>I would like to use Lua in a "financial" context, where using "doubles" for floating point decimal numbers is not enough regarding to precision.
>Indeed, dealing with large monetary values may trigger overflows in the calculations... I certainly do not want this to happen.
>
>Is there a way, using the LNUM patch, to circumvent this? I have thought about using an int64 for numbers and associating a second number to indicate where the decimal point is located. Another option would be to use BCD like some databases do (ORACLE for instance) to deal with arbitrary precision decimals.
>
>What do you think? Is LNUM the way to go (with some improvements), or should I instead use some available BCD library? (or implement it by myself).

I don't know anything about the LNUM patch, but years ago when I had a
similar problem in C++, I handled it by making a class containing a
double and a short. The double was used to store the digits of the
value as an integer, without any decimals, and the short was used to
store the position of the decimal. Since a double can handle 16-digit
integers, a solution like this should be enough for almost any
financial transactions.

Steve