patternsqlModerate
Biggest possible double/float for a column in my MySQL database
Viewed 0 times
columnfloatdatabasebiggestpossibledoublemysqlfor
Problem
I am developing a PHP application in which I am in need to store values bigger than 1 million, but with the flexibility of having floating points. I know the traditional float and double. I am looking to store only up to two decimal points, and will only handle operations with numbers that have 2 decimals exclusively.
I have chosen my column type of double and unsigned, but whenever I store a row with a value bigger than one million, it gets truncated to 999999.99
Why is this? I am looking for the right datatype/solution. If you could point me in the right direction, I will appreciate it a lot!
Thank you for your time in advance!
Cheers.
I have chosen my column type of double and unsigned, but whenever I store a row with a value bigger than one million, it gets truncated to 999999.99
Why is this? I am looking for the right datatype/solution. If you could point me in the right direction, I will appreciate it a lot!
Thank you for your time in advance!
Cheers.
Solution
Do not use
Your question is vague -- are you storing "money"? If so, then you really should use
(m,n) on the end of FLOAT or DOUBLE. That causes a rounding (at the bottom) or a truncation (at the top). If you want (m,n), you probably should use DECIMAL(m,n).FLOAT stores 24 significant bits of data (equivalent to about 7 decimal digits; storage=4 bytes), with an exponent ranging over about 10 ** +/-38.DOUBLE stores 53 bits (about 16 digits, 8 bytes) and has a huge range.Your question is vague -- are you storing "money"? If so, then you really should use
DECIMAL(m,2). m=8 lets you store up to a million dollars (or Euros, etc). But m can be as big as you want. (Remember to subtract the 2 before seeing how big the numbers can be.) (14,2) would store up to a trillion dollars, with precision to the penny. It will take 8 bytes of storage.Context
StackExchange Database Administrators Q#144920, answer score: 10
Revisions (0)
No revisions yet.