Saving Bitcoin data in Mysql

Hi Guys,

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
decimal(20,20)
double(20,20) –> got converted to decimal(20,20)
float(20,20)

I tried to save this value 123456789,123456789
But it always got rounded out or misrepresented.

Results
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.

Any suggestions?

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.

Thank you Rubble !
Great advice there…

It worked with (20, 8)

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?

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.