[英]SQL ROUND() function issue
我試圖使用round
函數將例如348.426580
轉換為348.43
但是在下面的查詢中,我使用了[ShippingCost]
列中的結果為348.430000
如何省略四個零?
SELECT S.Product_Name,
SPD.UnitPrice,
SPD.Quantity,
SPD.Quantity * SPD.UnitPrice Amount,
CONVERT(INT,(SPD.Quantity * SPD.UnitPrice)/(SUM(SPD.Quantity * SPD.UnitPrice) OVER()) * 100) [Cost %],
ROUND((SPD.Quantity * SPD.UnitPrice)/(SUM(SPD.Quantity * SPD.UnitPrice) OVER()) * Sp.Shipping_Cost,2) [ShippingCost],
(SPD.Quantity * SPD.UnitPrice)/(SUM(SPD.Quantity * SPD.UnitPrice) OVER()) * Sp.Customs_Cost [CustomsCost],
(SPD.Quantity * SPD.UnitPrice)/(SUM(SPD.Quantity * SPD.UnitPrice) OVER()) * Sp.Shipping_Cost + (SPD.Quantity * SPD.UnitPrice)/(SUM(SPD.Quantity * SPD.UnitPrice) OVER()) * Sp.Customs_Cost +SPD.Quantity * SPD.UnitPrice - SpD.Discount [TotalAmount]
FROM dbo.Stock_Purchase SP
INNER JOIN dbo.Stock_Purchase_Details SPD
ON SP.Purchase_ID = SPD.Purchase_ID
INNER JOIN dbo.Store S
ON SPD.Pro_ID = S.Pro_ID;
您可以將其DECIMAL(10, 2)
轉換為小數,例如DECIMAL(10, 2)
。 因為強制轉換會自動進行舍入,所以不需要round()
:
CAST((SPD.Quantity * SPD.UnitPrice)/(SUM(SPD.Quantity * SPD.UnitPrice) OVER()) * Sp.Shipping_Cost as decimal(10, 2)) as [ShippingCost],
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.