为什么我这样做:
select CAST(1 AS DECIMAL(38, 28))/CAST(1625625 AS DECIMAL(38, 28))
我得到 0,但是当我得到 p>
select CAST(1 AS DECIMAL(20, 10))/CAST(1625625 AS DECIMAL(20, 10))
我得到一个值?
我本来期望更高精度的除法会返回更高精度的结果,为什么不是这样?
最佳答案
发生这种情况是因为对于数学运算,结果精度和比例是根据 http://msdn.microsoft.com/en-us/library/ms190476.aspx#division 中的规则计算的
operation
e1 / e2result precision
p1 - s1 + s2 + max(6, s1 + p2 + 1)result scale
max(6, s1 + p2 + 1)
因此,当对两个部分都使用 decimal(38/28)
时,您将以 decimal(105,67)
结尾,这不受支持,因此它会被截断。
也引用
The result precision and scale have an absolute maximum of 38. When a result precision is greater than 38, the corresponding scale is reduced to prevent the integral part of a result from being truncated.
关于sql - 小数除以小数并得到零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21169231/