Question : How can I compare float data?

I have two tables tableA(EmpID INT ,Revenue FLOAT ) and tableB(EmpID INT ,Revenue FLOAT). EmpID is Primary key in both the tables.
These two tables should have same data which I am validating with the below script.

SELECT A.EmpID,A.Revenue,B.EmpID,B.Revenue FROM tableA A FULL JOIN tableB B ON A.EmpID = B.EmpID WHERE A.Revenue <> B.Revenue
Ideally this query should not return any record if all employees have same revenue in both tables. But my query results few records like below.

A.EmpID     B.EmpID   A.Revenue             B.Revenue
88476        88476        2529203.82645      2529203.82645
119339       119339        81986.47085      81986.47085

Eventhough the revenues are matching in both tables, still those records are displayed.

I run the below query to get the exact difference between revenues in both tables.

SELECT A.EmpID,A.Revenue,B.EmpID,B.Revenue,A.Revenue - B.Revenue AS Diff1,ROUND(A.Revenue,4),ROUND(B.Revenue,4),
       ROUND(A.Revenue,4) - ROUND(B.Revenue,4) AS Diff2
  FROM tableA A FULL JOIN tableB B ON A.EmpID = B.EmpID WHERE ROUND(A.Revenue,4) <> ROUND(B.Revenue,4)

But this time also, i got the records and the result set is:

A.EmpID    B.EmpID   A.Revenue            B.Revenue           Diff1                                  ROUND(A.Revenue,4)   ROUND(B.Revenue,4)   Diff2
88476       88476       2529203.82645    2529203.82645   4.65661287307739E-10    2529203.8265              2529203.8264      9.99998301267624E-05
119339      119339      81986.47085      81986.47085      -1.45519152283669E-11      81986.4708      81986.4709      -0.000100000004749745

How can i compare the data so that it should not return these matching records?

Answer : How can I compare float data?

do a convert.  Float is an approximation - great for hugely exponentiated numbers and scientists, not so good for accounting. It will convert properly, you just need to ascertain the scope or decimal places...

Use :  convert(decimal(18,6), a.revenue)    when you go to use it... such as :

SELECT A.EmpID,A.Revenue,B.EmpID,B.Revenue,A.Revenue - B.Revenue AS Diff1,convert(decimal(18,6), a.revenue),convert(decimal(18,6), b.revenue),
       convert(decimal(18,6), a.revenue) - convert(decimal(18,6), b.revenue) AS Diff2
  FROM tableA A FULL JOIN tableB B ON A.EmpID = B.EmpID WHERE convert(decimal(18,6), a.revenue) <> convert(decimal(18,6), b.revenue)
Random Solutions  
 
programming4us programming4us