Sql Server 2005 Data Types

What is the difference between real, floating, decimal and monetary. And most importantly, when I use them. As I understand it - real and floating approx. types, that is, they do not store the exact meaning. Why do you need this?

thank

+2


source to share


2 answers


real and floating numeric types are useful for handling a very wide range of values โ€‹โ€‹that occur with physical dimensions or mathematical results.

The loss of precision they incur, for example when adding values โ€‹โ€‹that are not in the same range, such as 0.00002468 + 1.23E9 (i.e. 1.230.000), is usually acceptable for practical purposes. This is a small tribute to the relatively compact storage requirements of these floating point types.

Decimal and currency types do not cover such a wide range (although they do cover ranges that are outside the scope of most typical accounting applications), and do not exhibit any such round-loss behavior, etc.



Please refer to the MS-SQL document for details. The following table shows the approximate accuracy, range, and storage requirements for the various types.

Type Max value precision (*) Storage
money +/- 922,000,000,000,000 3 (4?) 8 bytes
smallmoney +/- 200,000 3? 4 bytes
decimal varies (as defined) varies varies 3 to 17

real +/- 3.4 * 10 ^ 38 7 digits 4 bytes
float "56" +/- 1.7 * 10 ^ 308 15 digits 8 bytes (float can also be declared to be just like a real)       

(*) precision: for "exact" types, this is the number of digits after the decimal point. For โ€œunprofitableโ€ reales and floats, this is the number of significant digits.

+2


source


Money is a precise data type. since it is continuous between its upper and lower boundaries. You usually use it when you want to store money and don't want to lose precision and get round-off errors caused by IEEE754. Decimal is exactly the same data type and is not loss-making up to a certain number of decimal places (which you can specify). Real is equivalent to float (24).

To be clear, precision loss can occur when using division, but all other basic math operations do not suffer a loss of precision for Currency and Decimal types.



See here for an explanation of the different Transact SQL data types.

+1


source







All Articles