SQLite Forum

The NUMERIC data type?
> It's really a pity that SQLite doesn't implement a true DECIMAL/NUMERIC data type

Isn't that tantamount to lamenting the fact that SQLite isn't an [arbitrary precision arithmetic][1] engine? What's "Lite" about that?

If you want APA, strap one of the [many available engines][2] to SQLite, then store the results in SQLite columns. Depending on your needs, you might store the calculated data as:

* strings to allow stringwize `max()` and such if you zero-pad the results; or
* BLOBs containing some binary representation of the APA data structure; or
* large integers, multiplied up to strip the fractional part (e.g. ×100 for US cents to dollars); or
* multiple columns containing a serialized form of the APA data structure (e.g. two ints for mantissa and exponent)

> binary floating point types are not precise and therefore unusable for commercial calculations

That depends on how it's done. If you use [epsilon values][3] carefully, you can keep things quite nicely on the rails using FP arithmetic.

Or, you can do everything with integer math (e.g. calculate on cents rather than dollars for US monetary calculations) and treat fractional dollars as a presentation issue.

[1]: https://en.wikipedia.org/wiki/Arbitrary-precision_arithmetic
[2]: https://en.wikipedia.org/wiki/List_of_arbitrary-precision_arithmetic_software
[3]: https://en.wikipedia.org/wiki/Machine_epsilon