What's the decimal storage requirement in ms sql for bitcoin?
GAAP standard quotes decimal (13, 4) for money.
Is decimal (13,8) preferred for bitcoin or something else?
Bitcoin Stack Exchange is a question and answer site for Bitcoin crypto-currency enthusiasts. It only takes a minute to sign up.
Sign up to join this communityWhat's the decimal storage requirement in ms sql for bitcoin?
GAAP standard quotes decimal (13, 4) for money.
Is decimal (13,8) preferred for bitcoin or something else?
Since Bitcoin's precision is 8 decimal numbers, decimal (13, 4) won't cut it. So you better go with (13, 8).
DECIMAL(13,8)
will fail should you ever encounter an amount of BTC 100000.00000000 or larger. As the other answer says, DECIMAL(16,8)
would be safe until/unless the protocol changes to further subdivide the bitcoin or expand the money supply.
Oct 14, 2014 at 14:24
You need at least DECIMAL(16,8)
to store any valid Bitcoin amount (i.e. up to just over 20 Million Bitcoin, requiring 8 digits to the left of the decimal point) precisely (i.e. down to a single Satoshi, requiring 8 digits to the right of the decimal point).
Depening on your application and how you (or your collaborators) think of Bitcoin amounts, it may be preferable to process them in Satoshi, enabling you to treat them as integers (BIGINT
would then be the SQL datatype). Of course, then you have traded the dangers around non-integer handling for those associated with large integer handling.
I would take a different approach and simply use an 8-byte integer value. This is because all bitcoin transaction values are stored as integers and since float decimal math can vary from architecture to architecture, I'd recommend using integer values whenever possible.
Bitcoin has a fixed decimal place of 8-digits. If you want to display this information to an end-user just format the integer value to represent the appropriate number of decimals, when the value needs to be displayed.
int
type in sql and only format the value when it needs to be displayed to the end-user. Surely any accountant within any computational background would recommend the same approach. Especially if they've worked int he field of transactional processing. ;)
DECIMAL(13,4)
as the largest amount representable is $999,999,999.9999. Every company in the Fortune 1000 has revenues higher than that.