TSQL 四舍五入到小数点后半 [英] TSQL round to half decimals

查看:51
本文介绍了TSQL 四舍五入到小数点后半的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想四舍五入到最接近的小数点(地理坐标)以进行一些数据可视化.在 t-sql 中,是否有一个内置函数可以四舍五入到小数点的一半(如果是这个词的话).所需结果示例:

I want to round to the nearest half decimals (geo coordinates) to do some data visualization. In t-sql, is there a built in function to round to half decimals (if that is the term). Examples of desired result:

    1.1 > 1.0
    1.4 > 1.5
    1.6 > 1.5
    1.9 > 2.0

推荐答案

只需乘以 2,取整,再除以 2.

Just multiply by 2, round, and divide by 2.

select round(1.1 * 2, 0) / 2 -- > 1.0
select round(1.4 * 2, 0) / 2 -- > 1.5
select round(1.6 * 2, 0) / 2 -- > 1.5
select round(1.9 * 2, 0) / 2 -- > 2.0

MSDN 上的回合

这篇关于TSQL 四舍五入到小数点后半的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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