SQL Multiply Discrepancy
I stumbled across this oddity when multiplying DECIMAL
numbers on SQL Server 2005/2008. Can anyone explain the effect?
DECLARE @a DECIMAL(38,20)
DECLARE @b DECIMAL(38,20)
DECLARE 开发者_运维问答@c DECIMAL(38,20)
SELECT @a=1.0,
@b=2345.123456789012345678,
@c=23456789012345.999999999999999999
SELECT CASE WHEN @a*@b*@c = @c*@b*@a
THEN 'Product is the same'
ELSE 'Product differs'
END
It's due to precision representation and rounding errors.
The problem is due to
SELECT @a*@b --(=2345.123457)
[Please search SO for multiple examples.]
Related: Sql Server Decimal(30,10) losing last 2 decimals
精彩评论