请查看下面的代码并向我解释为什么最终结果会出现偏差。请注意,不同之处在于第二次计算中引入了括号。谢谢!
代码:
DECLARE @A decimal(38,19) = 7958011.98
DECLARE @B decimal(38,19) = 10409029441
DECLARE @C decimal(38,19) = 10000000000
DECLARE @Z1 decimal(38,19)
DECLARE @Z2 decimal(38,19)
SET @Z1 = @A * @B / @C
SET @Z2 = @A * (@B / @C)
SELECT @Z1 AS [Correct],
@Z2 AS [Wrong]
结果:
Correct = 8283518.0991650000000000000
Wrong = 8283510.5860060000000000000