在 SQL 中四舍五入到 0.5 或 1.0

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9873990/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 15:01:14  来源:igfitidea点击:

Round to .5 or 1.0 in SQL

sqltsqlnumbersdecimalrounding

提问by Sandeep Bansal

I'm looking to round values like

我正在寻找四舍五入的值

2.3913 -> 2.5

4.6667 -> 4.5

2.11 -> 2

2.3913 -> 2.5

4.6667 -> 4.5

2.11 -> 2

How can I manage this in SQL?

如何在 SQL 中管理它?

Thanks

谢谢

回答by Paul

SELECT ROUND(2.2 * 2, 0) / 2 

gets you to the nearest .5

让你到最近的 0.5

回答by Chris D'mello

round(round(column/5,1)*5,1)closest 0.5
round(round(column/5,2)*5,2)closest 0.05

round(round(column/5,1)*5,1)最接近 0.5
round(round(column/5,2)*5,2)最接近 0.05