tags:

views:

41

answers:

5

Someone mentioned in this http://stackoverflow.com/questions/1165761/answer 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?

A: 

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.

Oded
I guess I was asking both. What data type should I use in C# and what is the SQL Server equivalent? I'm saving the value of measurements like temperature, flashpoint, viscosity. I'm currently using Float in SQL and double in C#.
HackITMngr
@HackITMngr - see this SQL-CLR type mapping on MSDN. Should give you a good idea of what maps to what. Float and Double are a good match. http://msdn.microsoft.com/en-us/library/bb386947.aspx
Oded
A: 

when-should-i-use-double-instead-of-decimal

decimal-vs-double-which-one-should-i-use-and-when

Muhammad Kashif Nadeem
Those questions and answers deal with C#, not SQL. Perhaps you could at lease summarize the info in those links in your answer?
Oded
@Oded you are right but in these questions it is explained in great details. So, I think, there is no need to repeat what is already available. You have also answered it good so the purpose is solved.
Muhammad Kashif Nadeem
+1  A: 

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.

gbn
thanks for the quick responses. I'll go with float on the sql side
HackITMngr
A: 

Generally you would always use doubles for recording physical measurements unless you have a good reason to do otherwise. There is potentially a miniscule loss of accuracy when using any floating point number since binary is unable to perfectly represent certain decimal numbers (0.1 being the most obvious example) but the inaccuracy in the double representation is going to be many orders of magnitude smaller than the error in the measurements you take.

Decimal is used where it's very important that numbers are represented exactly so typically only when dealing with money (yes, it would seem we care more about money than science!)

wobblycogs
A: 

Knowing which database this is for would make things easier...

Oracle only has NUMBER, which if you omit the two optional parameters precision and scale - is a float. Using both parameters is DECIMAL, and only specifying the precision is INTEGER. Can't remember how to get REAL...

MySQL Numeric data type info: http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html

SQL Server Numeric data type info: http://msdn.microsoft.com/en-us/library/aa258271(SQL.80).aspx

I haven't dealt with float and real much, but I've heard they aren't great for mathematical computations. I've used DECIMAL for varying precision, not just for monetary values.

What data type to use depends on the data, and how you intend to use that data.

OMG Ponies