MySQL ROUND 函数使用向下舍入而不是向上舍入 [英] MySQL ROUND function using round half down instead of half up

查看:33
本文介绍了MySQL ROUND 函数使用向下舍入而不是向上舍入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我正在运行 MySQL 5.1.4 版,我正在尝试通过舍入值选择不同的值,它的效果很好,只是它将数字舍入为 12.5 到 12 而不是 13.我尝试过的列都是双精度型.我做了一些研究,发现默认行为是四舍五入,所以我想知道是否有一些设置或参数需要更改,或者是否只是坏了?

So I'm running MySQL version 5.1.4 and I'm trying to select distinct by a rounded value, and it works great except that it rounds numbers like 12.5 to 12 instead of 13. The columns I have tried this on have all been type double. I did a bit of research and saw the default behavior is to round half up so I'm wondering if there is some setting or parameter I need to change or if this is just broken?

这是我的查询以供参考:SELECT DISTINCT ROUND(radius) as radius FROM arch WHERE radius != '' ORDER BY radius ASC

Here is my query for reference : SELECT DISTINCT ROUND(radius) as radius FROM arch WHERE radius != '' ORDER BY radius ASC

推荐答案

参见 这个.将 radius 列转换为 DECIMAL 应该可以解决问题.

See this. Converting the radius column to DECIMAL should solve the problem.

这篇关于MySQL ROUND 函数使用向下舍入而不是向上舍入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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