SQLite Forum

Decimal128
Login
**Proposed:** A new extension to implement infinite-precision decimal
arithmetic on strings.  The extension would consist of the following
SQL functions:

  *  decimal_add()
  *  decimal_sub()
  *  decimal_mul()
  *  decimal_div()

And a single new [collating function][2]:

  *  DECIMAL

The functions would take two or three arguments.  The first two arguments
are strings that are interpreted as decimal numbers.  The third argument
is a non-negative integer which is the number of digits of precision after
the decimal-point to preserve.  If the third argument is omitted, the value
used is the larger of the two input numbers.

The DECIMAL collating function compares two decimal number strings in
numeric order.  It works similar to [UINT collating function][1] in that
it compares strings in numeric order.  The difference is that DECIMAL
does not access text intermixed with the strings, but it does work with
negative numbers and decimal points.

**Examples:**

  *  decimal_add('123.4','3450.67',4)  →  '3574.0700'
  *  decimal_div('123.4','3450.67',30) →  '0.035761171018961535050806332947'
  *  '123.4' < '3450.67' COLLATE DECIMAL &rarr; TRUE

[1]: https://www.sqlite.org/uintcseq.html
[2]: https://www.sqlite.org/datatype3.html#collation