SQL SERVER – Difference and Explanation among DECIMAL, FLOAT and NUMERIC

The basic difference between Decimal and Numeric :
They are the exactly same. Same thing different name.

SQL SERVER - Difference and Explanation among DECIMAL, FLOAT and NUMERIC

The basic difference between Decimal/Numeric and Float :
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 reane can be represented exactly with precision and scale.

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.

Choosing Between DECIMAL and FLOAT in Real Tables

My simple rule: use an exact type for anything people will add up and check, like money, quantities and rates. Use FLOAT for scientific values, measurements and calculations where tiny rounding differences do not matter.

The exact types take a precision and a scale. Precision is the total number of digits, and scale is the number of digits after the point. The largest precision is 38. If you leave them out, you get a precision of 18 and a scale of 0, so CAST(1.5 AS NUMERIC) returns 2, not 1.5. Always write both numbers.

Storage grows with precision: 5 bytes for up to 9 digits, 9 bytes up to 19, 13 bytes up to 28 and 17 bytes up to 38. Pick the precision you really need rather than the maximum, since every extra byte is repeated in every row and every index that holds the column.

With FLOAT, avoid comparing values with =. Two calculations that should give the same answer can differ in the last digit and fail the test. Compare with a small tolerance, or round both sides first. FLOAT(24) and below is stored in 4 bytes, and FLOAT(25) up to FLOAT(53) in 8 bytes. When in doubt, choose the exact type, because a total that matches to the cent is much easier to explain.

Published by Pinal Dave on SQLAuthority. More of my work at pinaldave.com.

SQL Datatype, SQL Scripts
Previous Post
SQL SERVER – 2005 – Use Always Outer Join Clause instead of (*= and =*)
Next Post
SQL SERVER – 2005 – Find Database Collation Using T-SQL and SSMS

Related Posts

93 Comments. Leave new

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.