Давайте начнем с диапазона BigInt
: от -2 ^ 63 (-9,223,372,036,854,775,808) до 2 ^ 63-1 (9,223,372,036,854,775,807). Это примерно ± 9E + 18, поэтому -4,66606E + 22 маловероятно BigInt
значение.
Переходя к сравнению значений разных типов данных:
declare @Foo as BigInt = 8765432109876543210;
declare @FloatFoo as Float(24) = @Foo, @DoubleFoo as Float(53) = @Foo;
-- According to the rules for data type preedence a BigInt value will be converted to a Float
-- when the two data types are compared. Hence all of the values are "equal".
select @Foo as Foo,
@FloatFoo as FloatFoo, case when @Foo = @FloatFoo then 1 else 0 end as FloatMatch,
@DoubleFoo as DoubleFoo, case when @Foo = @DoubleFoo then 1 else 0 end as DoubleMatch;
-- Since a Float(53) has a precision of 15 digits that means some precision will be lost.
set @Foo += 1; -- Bump the BigInt value, but leave the Floats unchanged.
-- And ... the values are all still "equal"!
select @Foo as Foo,
@FloatFoo as FloatFoo, case when @Foo = @FloatFoo then 1 else 0 end as FloatMatch,
@DoubleFoo as DoubleFoo, case when @Foo = @DoubleFoo then 1 else 0 end as DoubleMatch;
-- Once more, with feeling.
set @Foo += 1000; -- A bigger bump makes the Float(53) value different, but not the Float(24).
select @Foo as Foo,
@FloatFoo as FloatFoo, case when @Foo = @FloatFoo then 1 else 0 end as FloatMatch,
@DoubleFoo as DoubleFoo, case when @Foo = @DoubleFoo then 1 else 0 end as DoubleMatch;
Ссылка: Приоритет типа данных , Float
.
Резюме: «Имеются неверные данные со значением bigint
. Значение -4.66606E+22
.» Это действительно плохие данные. А сравнение значений BigInt
и Float
- неточное действие, которое может привести к разочарованию.