gpt4 book ai didi

MySQL 舍入行为没有按预期工作..?

转载 作者:太空宇宙 更新时间:2023-11-03 10:36:38 24 4
gpt4 key购买 nike

可以找到 MySQL 舍入行为术语 here. .他们 promise Approximate(FLOAT, DOUBLE) 值的舍入将为 HALF_EVEN。但是当尝试相同的时候,我无法产生文件中所说的内容。对于 DOUBLE 数据类型,它显然可以用作 HALF_UP。我在这里遗漏了什么 ..?

CREATE TABLE `doubleValues` (
`val` double DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

select* from doubleValues;
+-------+
| val |
+-------+
| 1.245 |
| 0.555 |
+-------+

select round(val,2) from doubleValues;
+--------------+
| round(val,2) |
+--------------+
| 1.25 |
| 0.56 |
+--------------+
2 rows in set (0.00 sec)

最佳答案

来自您将请求链接到的文档:

For approximate-value numbers, the result depends on the C library. On many systems, this means that ROUND() uses the “round to nearest even” rule: A value with any fractional part is rounded to the nearest even integer.

换句话说:舍入方法未定义。

无论如何:为什么要使用近似类型?您需要那么多位数的号码吗?我很难想象一个数据库会是这种情况。也许是一些天文数据库。

关于MySQL 舍入行为没有按预期工作..?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47159686/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com