Crypto Currency MySQL Data Types?

A shameful question about data types when storing monetary values ​​in an SQL database.

However, in these difficult times, we now have currencies that can cost up to 18 decimal places (thanks ETH).

Now this repeats the classic argument.

IDEAS

Option 1 BIGINT Use a large integer to keep the real value, and then save how many decimal places the currency has (just dividing Aby 10^Bthe translation)?

Option 2 Decimal(60,30) Save the data type in a large decimal value, which will inevitably cost a large amount of space.

Option 3 VARCHAR(64) Save to line. This will affect performance.


I want to know people's thoughts and what they use if they are dealing with cryptocurrency values. Because I'm downplaying the best way to continue.

+4
source share
1 answer

There is the best best option out of three that you proposed (plus one of the comments).

BIGINT - uses only 8 bytes, but the largest BIGINThas only 19 decimal digits; if you divide by 10 18 the largest value you can imagine is 9.22, which is not enough for the range.

DOUBLE - has only 15-17 decimal digits of accuracy; has all the known disadvantages of floating point arithmetic.

VARCHAR - 20 + , 18 ; string; ; ; ; .

DECIMAL (27,18) - MySQL 12 (4 9 ). , , Wei. , , , .. .

DECIMAL(27,18) ( DECIMAL(36,18), - ), .

+3

Source: https://habr.com/ru/post/1687185/


All Articles