Documentation for SQL Server Float says
Approximate number data types for use with floating point numeric data. Floating-point data are approximate; therefore, not all values in the data type of the type can be represented exactly.
This is what I expected from him. If so, but why is the next return "Yes" in SQL Server (unexpected)
DECLARE @D float
DECLARE @E float
set @D = 0.1
set @E = 0.5
IF ((@D + @D + @D + @D +@D) = @E)
BEGIN
PRINT 'YES'
END
ELSE
BEGIN
PRINT 'NO'
END
but the equivalent C ++ program returns “No” (it is expected that a value of 0.1 cannot be represented exactly, but maybe 0.5)
#include <iostream>
using namespace std;
int main()
{
float d = 0.1F;
float e = 0.5F;
if((d+d+d+d+d) == e)
{
cout << "Yes";
}
else
{
cout << "No";
}
}
source
share