公式扩展字段和舍入无法弄清楚

时间:2018-01-27 16:53:14

标签: mysql rounding

我有以下公式放入mySQL

SELECT Order_Number, 
Order_Date, 
Product, 
Quantity, 
Price, 
Commission, 
Employee_Sold, 
(Quantity*Price)*(Commission*.01) AS Commision_Paid 
FROM Orders 
WHERE Order_Date BETWEEN '2017-12-01' AND '2017-12-31' 

佣金支付金额以2.992500为例.....

佣金字段设置为十进制(5,2)。

在扩展字段(Commission_Paid)中,在这种情况下显示为2.99会很好。

我在很多地方尝试了ROUND功能,但我不确定是否一直收到错误信息。

提前致谢。学生在这里和我的论文截止日期。赞赏。

MySQL 5.5X正在运行。

1 个答案:

答案 0 :(得分:0)

使用Round(x,2)

SELECT Order_Number, 
Order_Date, 
Product, 
Quantity, 
Price, 
Commission, 
Employee_Sold, 
round((Quantity*Price)*(Commission*.01), 2) AS Commision_Paid 
FROM Orders 
WHERE Order_Date BETWEEN '2017-12-01' AND '2017-12-31'