SELECT `Product Name`, `Price`, `Modification`, `Description`, `Image`, (`Price` * (1 - (`DiscPercent` / 100))) AS `Discount`
FROM `products`
WHERE `Producer_ID` = '1'
AND `DiscPercent` > 0
如果我运行此查询,它将显示DiscPercent为999.9000。有什么办法让我只有2dp吗
最佳答案
使用round()
功能请按以下方式更改:
SELECT `Product Name`, `Price`, `Modification`,
`Description`, `Image`, round((`Price` * (1 - (`DiscPercent` / 100))),2)
AS `Discount`
FROM `products`
WHERE `Producer_ID` = '1'
AND `DiscPercent` > 0
关于mysql - 格式化方程式以仅显示2dp,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40130127/