What should I be using to store the values of a wallet in a MySQL database?
Apparently floats are too imprecise to be storing Bitcoins, especially down to the satoshi.
So what should I be using? Decimal ?
What should I be using to store the values of a wallet in a MySQL database?
Apparently floats are too imprecise to be storing Bitcoins, especially down to the satoshi.
So what should I be using? Decimal ?
What you want is a MySQL Decimal field.
Specifically you want a DECIMAL(16,8)
That will give you 8 digits before the decimal and 8 after the decimal
See http://dev.mysql.com/doc/refman/5.1/en/precision-math-decimal-changes.html for details.
There would be small expression errors. If you want to save as integers just multiply by 100000000 and save satoshis.
As @ypercube states MySQL BIGINT is a wise type choice for storing satoshis, MySQL INT does not have a sufficient maximum value.
a float natively only goes up to 7 decimals in most cases. if you just roll with decimal you'll be safe. When you round a 7 digit number to 8 decimal places you'll run into rounding issues.