我尝试使用round
函数将例如348.426580
转换为348.43
但在下面的查询中,我使用的结果是348.430000
列
[ShippingCost]
如何省略四个零?
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;
答案 0 :(得分:3)
您可以转换为小数,例如DECIMAL(10, 2)
。由于强制转换会自动进行舍入,因此不需要round()
:
CAST((SPD.Quantity * SPD.UnitPrice)/(SUM(SPD.Quantity * SPD.UnitPrice) OVER()) * Sp.Shipping_Cost as decimal(10, 2)) as [ShippingCost],
答案 1 :(得分:0)
Scanner in = new Scanner(System.in);
String[] input = new String[1000];
String[] output = new String[1000];
int x = 0;// All purpose counter
int y = 0;//Second purpose counter
boolean ends = false;
boolean starts = false;
/**
* This method is supposed to take the dna array and create an rna array from it to return
* to the main method wherever this method is called.
*
* @param String[] input The array that contains the dna sequence
* @return String[] output The array that contains the mRNA we just created in this method
*/
public void makeRNA()
{
System.out.println("Enter a simple DNA Sequence, make sure the amount of variables are a multiple of 3.");
String something = in.nextLine();
while(x < 1000)
{
if(something.indexOf(x) = "a")
{
output[x] = "u";
}
else if(input[x] == "c")
{
output[x] = "g";
}
else if(input[x] == "g")
{
output[x] = "c";
}
else if(input[x] == "t")
{
output[x] = "a";
}
x++;
}
for(x = 0 ; x < 1000; x++)
{
System.out.println(output[x]);
}
}
column_name要舍入的字段必需。
decimals必需指定要返回的小数位数。
See这个。