Precision、Scale、Sum、Divide..截断 [英] Precision, Scale, Sum, Divide.. Truncation
本文介绍了Precision、Scale、Sum、Divide..截断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码:
SELECT -701385.10 -- -701385.10
SELECT SUM(-701385.10) -- -701385.10
SELECT -701385.10/2889991754.89 -- -0.000242694498630
SELECT SUM(-701385.10)/2889991754.89 -- -0.000242
在最后一个 SELECT
中,结果被截断为 6 位小数.我已经通读了 Precision, Scale, and长度 文章,除非我的工作是错误的,否则我无法理解为什么会发生截断.表达式 SUM(-701385.10)
的类型应为 DECIMAL(38,2)
- 请参阅 SUM - 所以除法产生的类型应该有:
In the last SELECT
the result is truncated to 6 decimal places. I've read through the Precision, Scale, and Length article and unless my working is wrong, I can't understand why the truncation is occurring. The type of the expression SUM(-701385.10)
should be DECIMAL(38,2)
- see SUM - so the type resulting from the division should have:
精度:
- p1 - s1 + s2 + max(6, s1 + p2 + 1)
- 38 - 2 + 2 + 最大值(6, 2 + 10 + 1)
- 38 - 最大值(6,13)
- 38 - 13
- 25
比例:
- max(6, s1 + p2 + 1)
- 最大(6, 2 + 10 + 1)
- 最大(6, 13)
- 13
那么为什么小数位会被截断?
So why are the decimal places being truncated?
推荐答案
你的工作有问题
Precision: p1 - s1 + s2 + max(6, s1 + p2 + 1)
Scale: max(6, s1 + p2 + 1)
给予
Precision: 38 - 2 + 2 + max(6, 2 + 12 + 1) = 53
Scale: max(6, 2 + 12 + 1) = 15
大于 38 所以你会被截断 如此处所述
Which is greater than 38 so you are getting truncation as covered here
这篇关于Precision、Scale、Sum、Divide..截断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文