舍入数字的准确性 [英] Accuracy in rounding numbers

查看:42
本文介绍了舍入数字的准确性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下要求-

1. Get the A_MINUTES column value from TableA for all rows 
2. Sum the A_MINUTES. 
3. Convert the summed minutes values to hours - divide by 60 
4. Round off the final hours value to 2 decimal places.

这个需要用SQL写.

您认为此查询会有任何舍入错误吗?

Do you think this query will have any rounding errors?

SELECT ROUND ( (SUM(A_MINUTES)/60.0) , 2) FROM TABLEA

推荐答案

会不会有四舍五入错误?

Will it have any rounding errors?

这取决于您要实施的舍入方案.
您发布的 SQL 代码将实现您的目标,但 SQL 中的默认舍入方案不是像 .NET 中的默认方案那样的银行家舍入

That depends on what rounding scheme you want to implement.
The SQL code you posted will accomplish your goal but the default rounding scheme in SQL is not bankers rounding like the default scheme in .NET

http://msdn.microsoft.com/en-us/library/ms175003.aspx

以下是 SQL 中不同舍入方法实现的简要介绍:
http://blogs.lessthandot.com/index.php/DataMgmt/DataDesign/sql-server-rounding-methods

Here is a good brief on different rounding method implementations in SQL:
http://blogs.lessthandot.com/index.php/DataMgmt/DataDesign/sql-server-rounding-methods

如果您想实现银行家的舍入方案(如 .NET 中的默认设置),那么有几个选项.这是关于该主题的很好的讨论(适用于 Oracle,但应该适用)
http://www.orafaq.com/forum/t/122001/2/

If you wanted to implement a banker's rounding scheme (like the default in .NET) then there are a few options. Here is a good discussion on the topic (it is for Oracle, but should applicable)
http://www.orafaq.com/forum/t/122001/2/

这篇关于舍入数字的准确性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆