开发者

SQL Multiply Discrepancy

开发者 https://www.devze.com 2022-12-15 19:49 出处:网络
I stumbled across this oddity when multiplying DECIMAL numbers on SQL Server 2005/2008. Can anyone explain the effect?

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

0

精彩评论

暂无评论...
验证码 换一张
取 消