1

当我在 SQL Server 中执行此查询时:

SELECT
   Vt.Id, Vt.Description, 
   abs(Vt.Rate)as VRate,
   Sum(((itemprice * Qty) * (abs(Vt.Rate) / 100))) as VatAmount,
   Sum(itemprice * Qty) as NetAmount 
FROM
   BillItem1 as B1 
LEFT JOIN
   bill b ON b.orderid = b1.orderid
LEFT JOIN 
   ItemDescription ItD ON ItD.Id = B1.itemId 
LEFT JOIN
   VatType Vt on Vt.Id = ItD.TaxId 
WHERE 
   B1.IsActive = 1 
   AND B1.IsDelete = 0 
   AND b.date BETWEEN '11/09/2013 10:43:31 AM' AND '11/09/2013 10:43:31 AM' 
GROUP BY 
   Vt.Id, Vt.Rate, Vt.Description 
ORDER BY 
   SUM((b1.ItemPrice*Qty) - b1.NetAmount)DESC

输出是

在此处输入图像描述

当我与数据网格绑定时,它的显示如下输出

在此处输入图像描述

vatAmount列中显示小数点后很多零,所以我想从网格视图中减少零。

4

6 回答 6

2

您可以转换为带有 2 个小数点的十进制类型。

Select Vt.Id, Vt.Description, convert(decimal(20,2),abs(Vt.Rate)) as VRate,convert(decimal(20,2),Sum(((itemprice*Qty)*(abs(Vt.Rate)/100)))) as VatAmount ,convert(decimal(20,2),Sum(itemprice*Qty),)as NetAmount from BillItem1 as B1 left join bill b on b.orderid=b1.orderid
 Left JOIN ItemDescription ItD ON ItD.Id=B1.itemId Left Join VatType Vt on Vt.Id = ItD.TaxId where B1.IsActive=1 and B1.IsDelete = 0 and b.date between '11/09/2013 10:43:31 AM' and '11/09/2013 10:43:31 AM' Group By Vt.Id,Vt.Rate,Vt.Description Order By SUM((b1.ItemPrice*Qty) - b1.NetAmount)DESC
于 2013-11-09T06:06:27.170 回答
2

无论如何,基础价值是相同的。如何显示它是格式的问题。SQL 中的格式化通常是不必要的。格式化应该在从数据库系统接收数据的客户端上完成。

不要更改 SQL 中的任何内容。只需格式化您的网格以显示所需的位数。

于 2013-11-09T06:09:26.907 回答
1

您可以使用以下代码格式化显示的数据。此代码导致截断而不是舍入。

dataGridView1.DataSource=sometable; //bind to datasource

DataGridViewCellStyle style = new DataGridViewCellStyle();
style.Format = "N2";
this.dataGridView1.Columns["Price"].DefaultCellStyle = style;
于 2013-11-09T06:44:22.263 回答
0

在代码端转换数字。

前任。:

string.Format("{0:0.##}", 256.583); // "256.58"
string.Format("{0:0.##}", 256.586); // "256.59"
string.Format("{0:0.##}", 256.58);  // "256.58"
string.Format("{0:0.##}", 256.5);   // "256.5"
string.Format("{0:0.##}", 256.0);   // "256"
//===============================
string.Format("{0:0.00}", 256.583); // "256.58"
string.Format("{0:0.00}", 256.586); // "256.59"
string.Format("{0:0.00}", 256.58);  // "256.58"
string.Format("{0:0.00}", 256.5);   // "256.50"
string.Format("{0:0.00}", 256.0);   // "256.00"
//===============================
string.Format("{0:00.000}", 1.2345);    // "01.235"
string.Format("{0:000.000}", 12.345);   // "012.345"
string.Format("{0:0000.000}", 123.456); // "0123.456"

在你的情况下:

<asp:TemplateField HeaderText="VatAmount">
    <ItemTemplate>
        <%# string.Format("{0:0.00}", Eval("VatAmount").ToString()); %>
    </ItemTemplate>
</asp:TemplateField>
于 2013-11-09T06:07:53.673 回答
0

附上您的增值税金额round(,2)round(Sum(((itemprice*Qty)*(abs(Vt.Rate)/100))),2)

于 2013-11-09T06:11:07.663 回答
-2

您可以使用 Round 函数仅获取小数点后所需的位数。

double myValue = 23.8000000000000;
double newValue=Math.Round(myValue, 2);

结果:新值 = 23.8

于 2013-11-09T06:10:11.287 回答