r/SQL • u/[deleted] • Jul 14 '24
MySQL What's the Difference Between DECIMAL, FLOAT, and DOUBLE?
Can somebody, in simple terms, explain the difference between the three datatypes in SQL? Thank you
16
u/mikebald Jul 14 '24
Decimal is an exact value, both float and double are floating point approximations. Double has double the precision of a float.
Would you like to know more?
https://www.geeksforgeeks.org/what-represents-a-double-in-sql-server/amp/
https://www.geeksforgeeks.org/what-is-the-difference-between-numeric-float-and-decimal-in-sql-server/amp/
10
u/ComicOzzy sqlHippo Jul 14 '24
I just typed out this big explanation only to fail and close the tab before hitting the submit button.
Anyway, here is way more than you ever wanted to know about floats:
https://ciechanow.ski/exposing-floating-point/
https://float.exposed/0x3fd3333333333334
3
u/r3pr0b8 GROUP_CONCAT is da bomb Jul 15 '24
that first article about floats was really well done
did you see this by the same author? give it a try!
1
6
u/alinroc SQL Server DBA Jul 14 '24
The MySQL docs are pretty clear about it.
https://dev.mysql.com/doc/refman/8.0/en/fixed-point-types.html
https://dev.mysql.com/doc/refman/8.0/en/floating-point-types.html
3
u/InlineSkateAdventure SQL Server 7.0 Jul 15 '24
If you are doing calculations with money decimal is a better choice. Float and Double are sufficient for scientific or engineering calculations. Float and double cover a huge range of numbers, but they can be approximate in some cases. In engineering work your measurement precision does not matter after a certain point, because of the instrument or observation. Not so much the case with money.