T-SQL 舍入的正确方法
T-SQL 中以下正确的方法是什么?:
sum(rounded(fractions,2))
或 round(sum(offractions),2)
ta!
我尝试了这两种方法,但每种方法的总结果仍然不同。我不知道是否需要在某个地方截断。
我想要 x, y * @v = z,这样 sum(x) * @v = sum(z)。
what's the correct approach in T-SQL for the following?:
sum(rounded(fractions,2))
or round(sum(of fractions),2)
ta!
I've tried both approaches and got my total still end up with a different result for each. I don't know if I need to truncate somewhere.
I want x, y * @v = z, so that sum(x) * @v = sum(z).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是最准确的,因为您只在最后舍入一次。
另一方面,您在求和之前首先对每个单独的值进行舍入,因此最终结果很可能整体上不太准确。
编辑:非常基本的示例:
给出 Sum1=3.50 和 Sum2=3.60。
1.15+1.15+1.15 = 3.45(真实总计)。因此,Sum1 显然更准确
is most accurate, as you're only rounding once, right at the very end.
The other way, you are rounding each individual value first before summing so the end result will more than likely be less accurate all round.
Edit: very basic example:
gives Sum1=3.50 and Sum2=3.60.
1.15+1.15+1.15 = 3.45 (true total). Therefore, Sum1 is quite obviously more accurate