Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL data type for physical science measurements - double or decimal

Tags:

types

sql

Someone mentioned in this decimal vs double! - Which one should I use and when? post that it's best to use double for physical science computations. Does this apply to measurements such as flash point, viscosity, weight and volume? Can someone explain further?

like image 226
HackITMngr Avatar asked Sep 01 '25 17:09

HackITMngr


2 Answers

Decimal = exact. That is, I have £1.23 in my pocket and applying VAT, say, is a known and accepted rounding issue.

When you measure something, you can never be exact. If something is 123 centimeters long then strictly speaking it's somewhere between 122.5 and 123.49999 centimeters long....

You are dealing with 2 different kinds of quantities.

So, use double for this.

like image 106
gbn Avatar answered Sep 05 '25 07:09

gbn


The question you link to is about the data types in C#, not SQL, and the answers reflect that.

Decimal is a datatype used and created for dealing with currency, making sure calculations balance out (no lost cents or fractions of, for example).

Physical scientific computations rarely deal with money values, hence, you should use double whenever you need the accuracy.

like image 20
Oded Avatar answered Sep 05 '25 07:09

Oded