gpt4 book ai didi

mysql - 将数字格式化为 2 位小数

转载 作者:行者123 更新时间:2023-11-30 21:26:43 24 4
gpt4 key购买 nike

我想知道如何在不四舍五入原始数字的情况下输出小数点后两位的数字。

例如:

2229,999 -> 2229,99

我已经试过了:

FORMAT(2229.999, 2)
CONVERT(2229.999, DECIMAL(4,2))

最佳答案

将数字格式化为 2 位小数时,您有两个选项 TRUNCATEROUND。您正在寻找 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

关于mysql - 将数字格式化为 2 位小数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58562345/

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