Reputation: 488
Is there any reason to use a DOUBLE(n, 0) over a BIGINT(n) in MySQL? If the data will never have a decimal portion, is there any reason to store as a DOUBLE?
Upvotes: 5
Views: 12266
Reputation: 178966
There is only one reason to ever use DOUBLE
or FLOAT
in MySQL -- if scale and/or storage efficiency are important, but precision is not. This is not a limitation of MySQL, but rather of floating point numbers in general, which is that they are stored as approximate values.
Integers will be stored cleanly up to only about 2⁵³, which is smaller than BIGINT
. Most (though not all) integers beyond that range will be stored as a value that is only close to correct.
Floating-point numbers sometimes cause confusion because they are approximate and not stored as exact values. A floating-point value as written in an SQL statement may not be the same as the value represented internally. Attempts to treat floating-point values as exact in comparisons may lead to problems. They are also subject to platform or implementation dependencies.
For integers, use one of the *INT
types. For decimal, use DECIMAL
.
Upvotes: 5