Floating Point Calculation For Cryptocurrency

Floating point calculation for cryptocurrency

Floating point calculation for cryptocurrency

I know SQL 92 is old standard but iám pretty sure this is not changed in the newer SQL standard versions.

SQL 92 defines

73)Subclause 6.12, : When the data type of both operands of the addition.

subtraction, multiplication, or division operator is exact numeric, the precision of the result is implementation-defined."*

75)Subclause 6.12, : When the data type of either operand of an arithmetic operator is approximate numeric, the precision of the result is implementation-defined."*

The question is: and in the query a approximate or is it exact?

Binary 4 – Floating Point Binary Fractions 1


The answer is: you don't know also the database can't know.
So the database will run the implemention defined for MySQL and MariaDB engines this seams to be handled as datatypes

Why does Nick's answer return the correct values or expected ones with a table definition

SQL 92 also defines

Implicit type conversion can occur in expressions, fetch opera-
tions, single row select operations, inserts, deletes, and updates.
Explicit type conversions can be specified by the use of the CAST
operator.

Which Nick has done by defining the datatype in the table.

Edited this answer because i found something in the MySQL's manual today.

The query

Results into in MySQL which means MySQL uses exact numeric calculation and uses Precision Math where possible.

Floating point calculation for cryptocurrency

So the MySQL does know that , and are exact datatypes here and needs to calculate exact, like i was expecting before this edit.

Meaning the query

will run under the hood more or less like

Crypto trading vs stock trading