Crypto Currency MySQL Datatypes ? Crypto Currency MySQL Datatypes ? mysql mysql

Crypto Currency MySQL Datatypes ?


There's a clear best option out of the three you suggested (plus one from the comments).

BIGINT — uses just 8 bytes, but the largest BIGINT only has 19 decimal digits; if you divide by 1018, the largest value you can represent is 9.22, which isn't enough range.

DOUBLE — only has 15–17 decimal digits of precision; has all the known drawbacks of floating-point arithmetic.

VARCHAR — will use 20+ bytes if you're dealing with 18 decimal places; will require constant string↔int conversions; can't be sorted; can't be compared; can't be added in DB; many downsides.

DECIMAL(27,18) – if using MySQL, this will take 12 bytes (4 for each group of 9 digits). This is quite a reasonable storage size, and has enough range to support amounts as large as one billion or as small as one Wei. It can be sorted, compared, added, subtracted, etc. in the database without loss of precision.

I would use DECIMAL(27,18) (or DECIMAL(36,18) if you need to store truly huge values) to store cryptocurrency money values.