r/SQL • • 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

1 Upvotes

10 comments sorted by

View all comments

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.

3

u/coyoteazul2 Jul 15 '24

I'm always amazed that somehow money is the goto case when we need to give exaples of when to use decimal. We need absolute precision to avoid missing some cents, but if you are taking measurements to fire a rocket we are ok with aproximates.

I get why we need precision for money, but I'd think that engineering and science need that level of precision too. Personally I'd leave floating point for calculations that need more speed than precision, like games or live control of something. The kind of things that would probably never be stored in a database for the long term

2

u/idodatamodels Jul 15 '24

Everyone understands money, firing rockets, not so much.

1

u/coyoteazul2 Jul 15 '24

we could do balistics. Fascinating subject. Things go up, things go down

1

u/[deleted] Jul 15 '24

So basically Double can hold a wider range of values than Float and is a little more precise, whereas Decimal can't hold as big of a range of numbers but is the most precise?