marcel — 2014-01-21T15:02:12-05:00 — #1
I am trying to save Bitcoin data in Mysql. But I am struggling to identify a reliable data format that won't round out or misrespresent the original value.
Data Formated I tested
double(20,20) --> got converted to decimal(20,20)
I tried to save this value 123456789,123456789
But it always got rounded out or misrepresented.
decimal(20,20) --> 0.99999999999999999999
double(20,20) --> 0.99999999999999999999
float(20,20) --> 1.00000000000000000000
VarChar will work but I won't be able to do calculations within Mysql.
rubble — 2014-01-21T15:15:26-05:00 — #2
I believe at least for decimal you need say 20,10 which will be 20 digits with 10 in front of the decimal point and 10 after the decimal point.
I suggest you read the MySQL manual; here is the decimal page.
marcel — 2014-01-21T16:10:10-05:00 — #3
Thank you Rubble !
Great advice there...
It worked with (20, 8)
scallioxtx — 2014-01-24T18:31:29-05:00 — #4
Do you need to do any calculations with these values? If not, why not just store them as strings, thus ensuring the db will never change them?
I mean, what if for some reason a bitcoin comes along with 9 digits after the decimal point, the db will mangle it, and you lost yourself a bitcoin. From what I gather those things aren't cheap, so why risk it?
thereddevil — 2014-01-25T11:17:31-05:00 — #5
The column type DECIMAL is storing the value as a string.
As long as the OP make certain that the column length/size is large enough, DECIMAL is a better choice than VARCHAR on a number.
system — 2014-10-08T01:30:23-04:00 — #6
This topic is now closed. New replies are no longer allowed.