gpt4 book ai didi

MySql选择格式,圆列

转载 作者:行者123 更新时间:2023-11-29 07:02:26 25 4
gpt4 key购买 nike

我有一个表,其中包含具有如下列的产品:价格[小数 8,5] 和小数 [tinyint - 最大值为 5]。当我列出产品时,必须根据小数列中指定的小数显示价格。我试过这样的东西(用 mysql)

select p.price, round(p.price, p.decimals) as price, p.decimals
from product p

但它返回

100.35667   100.35700   3

我想成为 100。我还看到“Round”将不在我范围内的数字四舍五入。问候。

最佳答案

您需要FORMAT 函数:

http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_format

SELECT 
P.price,
FORMAT(P.price, P.decimals) as price,
P.decimals
FROM
product P;

关于MySql选择格式,圆列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9411656/

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