SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Guru marcel's Avatar
    Join Date
    Nov 2000
    Posts
    920
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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

    x0gGH68.png


    VarChar will work but I won't be able to do calculations within Mysql.

    Any suggestions?

  2. #2
    SitePoint Mentor silver trophy
    Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    2,430
    Mentioned
    82 Post(s)
    Tagged
    3 Thread(s)
    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.

  3. #3
    SitePoint Guru marcel's Avatar
    Join Date
    Nov 2000
    Posts
    920
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Rubble View Post
    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)

  4. #4
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,094
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    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?
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  5. #5
    SitePoint Wizard TheRedDevil's Avatar
    Join Date
    Sep 2004
    Location
    Norway
    Posts
    1,198
    Mentioned
    4 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by ScallioXTX View Post
    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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •