-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Emulate DECIMAL data type on SQLite #28
Comments
https://www.sqlite.org/datatype3.html
Given the above, for SQLite, it's better to use Using The alternative is to use string values like So, I'll probably have to document that if the emulated- |
It seems like JS doesn't have a decent fixed-point library that handles both precision and scale. There is https://github.com/MikeMcl/decimal.js/ but it only does precision and has a different model from the SQL standard. I really don't want to have to write my own... |
If you write something like
20 decimal places. If at least one of the numbers has more than 20 decimal places, the result has the same |
PostgreSQL, SELECT CAST(1.999 AS DECIMAL(10, 2))
> 2.00
SELECT CAST(1.991 AS DECIMAL(10, 2))
> 1.99 https://www.postgresql.org/docs/9.0/datatype-numeric.html#DATATYPE-NUMERIC-DECIMAL
|
PostgreSQL,
|
PostgreSQL, SELECT CAST(5.0 AS DECIMAL(2,1))/CAST(9.0 AS DECIMAL(2,1))
> 0.55555555555555555556 |
PostgreSQL, SELECT 1.1 * 1.23
> 1.353 The scale is sum of the scale of operands For addition, [Edit] |
MySQL sort of follows PostgreSQL for the most part, ignoring division and implicit minimum scale |
May be helpful to consult this for the API of the emulation https://github.com/tc39/proposal-decimal For division, |
For better division results, maybe this? This tells us how many digits we need for the division, in advance |
Use case:
For testing with SQLite,
#27
Also nice to have
DECIMAL
data type on SQLite for regular applications.Can probably emulate with
TEXT
and user defined functions (sqlite3_create_function()
).The text was updated successfully, but these errors were encountered: