我想知道如何在不四舍五入的情况下输出一个小数点后 2 位的数字。
例如:
2229,999 -> 2229,99
我已经试过了:
FORMAT(2229.999, 2)
CONVERT(2229.999, DECIMAL(4,2))
最佳答案
将数字格式化为 2 位小数时,您有两个选项 TRUNCATE
和 ROUND
。您正在寻找 TRUNCATE
函数。
例子:
不四舍五入:
TRUNCATE(0.166, 2)
-- will be evaluated to 0.16
TRUNCATE(0.164, 2)
-- will be evaluated to 0.16
文档:https://dev.mysql.com/doc/refman/8.0/en/mathematical-functions.html#function_truncate
四舍五入:
ROUND(0.166, 2)
-- will be evaluated to 0.17
ROUND(0.164, 2)
-- will be evaluated to 0.16
文档:https://dev.mysql.com/doc/refman/8.0/en/mathematical-functions.html#function_round
https://stackoverflow.com/questions/11190668/