Float vs. Decimal data types in SQL Server | Quisitive
Float vs. Decimal data types in SQL Server
June 25, 2009
Quisitive
Learn when to use float and decimal

In this blog, you will find float vs. decimal data types in SQL server and their uses.

Learn when to use float and decimal . Float stores an approximate value and decimal stores an exact value.

In summary, exact values like money should use decimal, and approximate values like scientific measurements should use float.

Here is an interesting example that shows that both float and decimal are capable of losing precision. When adding a number that is not an integer and then subtracting that same number float results in losing precision while decimal does not:

DECLARE @Float1 float, @Float2 float, @Float3 float, @Float4 float;
SET @Float1 = 54;
SET @Float2 = 3.1;
SET @Float3 = 0 + @Float1 + @Float2;
SELECT @Float3 – @Float1 – @Float2 AS “Should be 0”;
Should be 0
———————-
1.13797860024079E-15

When multiplying a non integer and dividing by that same number, decimals lose precision while floats do not.

DECLARE @Fixed1 decimal(8,4), @Fixed2 decimal(8,4), @Fixed3 decimal(8,4);
SET @Fixed1 = 54;
SET @Fixed2 = 0.03;
SET @Fixed3 = 1 * @Fixed1 / @Fixed2;
SELECT @Fixed3 / @Fixed1 * @Fixed2 AS “Should be 1”;
Should be 1
—————————————
0.99999999999999900

SQL Server 2008 and 2008 R2 End of Life

As you may know, SQL Server 2008 and SQL Server 2008 R2 reached their end of support on July 9, 2019.

Simplify your migration from Windows and SQL Servers to Microsoft Azure with Quisitive. Quisitive will assess your current environment, plan your migration, build your Azure infrastructure, migrate your workloads, and optimize your environment.

Learn more about our Windows & SQL Server to Azure Migration program.