SQL 轮函数 [英] SQL Round Function

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

问题描述

round(45.923,-1) 给出的结果是 50.这是为什么呢?它是如何计算的?

round(45.923,-1) gives a result of 50. Why is this? How it is calculated?

(对不起,我误认为这个问题的早期版本建议值为 46)

推荐答案

SQL ROUND() 函数将数字四舍五入到一个精度...

The SQL ROUND() function rounds a number to a precision...

例如:

round(45.65, 1) 给出结果 = 45.7

round(45.65, 1) gives result = 45.7

round(45.65, -1) 给出结果 = 50

round(45.65, -1) gives result = 50

因为这种情况下的精度是从小数点开始计算的.如果是正数,那么它会考虑右侧的数字,如果 >= 5,则将其向上舍入,如果 <=4,则向下舍入......同样,如果它是负数,则计算左侧的精度小数点...如果 >= 5

because the precision in this case is calculated from the decimal point. If positive then it'll consider the right side number and round it upwards if it's >= 5, and if <=4 then round is downwards... and similarly if it's negative then the precision is calculated for the left hand side of decimal point... if it's >= 5

例如 round(44.65, -1) 给出 40但是 round(45.65, -1) 给出了 50...

for example round(44.65, -1) gives 40 but round(45.65, -1) gives 50...

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

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