Difference between numeric, float and decimal in SQL Server

后端 未结 8 1419
半阙折子戏
半阙折子戏 2020-11-22 04:27

What are the differences between numeric, float and decimal datatypes and which should be used in which situations?

For any ki

8条回答
  •  北荒
    北荒 (楼主)
    2020-11-22 05:28

    Float is Approximate-number data type, which means that not all values in the data type range can be represented exactly.

    Decimal/Numeric is Fixed-Precision data type, which means that all the values in the data type range can be represented exactly with precision and scale. You can use decimal for money saving.

    Converting from Decimal or Numeric to float can cause some loss of precision. For the Decimal or Numeric data types, SQL Server considers each specific combination of precision and scale as a different data type. DECIMAL(2,2) and DECIMAL(2,4) are different data types. This means that 11.22 and 11.2222 are different types though this is not the case for float. For FLOAT(6) 11.22 and 11.2222 are same data types.

    You can also use money data type for saving money. This is native data type with 4 digit precision for money. Most experts prefers this data type for saving money.

    Reference 1 2 3

提交回复
热议问题