我有3个文本框,它们从3个已经使用该ROUND()
函数的SQL查询中接收一个int值。但是文本框中的结果返回4个小数点。.即,我需要该值,xxxxx.xx
但SQL查询却返回xxxx.xxxx
。
这是我的代码
private void totalRef_btn_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("Data source=10.0.0.3,1434;Initial Catalog=client_orders_test;**Logins omitted**");
SumTotalquery = "Select ROUND(SUM(value),2) from costings_cur";
SumExVatquery = "Select ROUND(SUM(value-(value*14/100)),2) from costings_cur";
SumVatquery = "Select ROUND(SUM(value*14/100),2) from costings_cur";
SqlCommand totalQry = new SqlCommand(SumTotalquery, conn);
SqlCommand exVatQry = new SqlCommand(SumExVatquery, conn);
SqlCommand vatQry = new SqlCommand(SumVatquery, conn);
conn.Open();
SqlDataReader DR1 = totalQry.ExecuteReader();
if (DR1.Read())
{
total_txtbox.Text = DR1.GetValue(0).ToString();
}
conn.Close();
conn.Open();
SqlDataReader DR2 = exVatQry.ExecuteReader();
if (DR2.Read())
{
exvat_txtbox.Text = DR2.GetValue(0).ToString();
}
conn.Close();
conn.Open();
SqlDataReader DR3 = vatQry.ExecuteReader();
if (DR3.Read())
{
vat_txtbox.Text = DR3.GetValue(0).ToString();
}
conn.Close();
}
我什至尝试使用此:
exvat_txtbox.Text = DR2.GetValue(0).ToString().Trim();
提前致谢
USEDecimal(18,2)
得到正确的结果
SELECT CAST(ROUND(SUM(value),2) AS DECIMAL(18,2)) FROM costings_cur
其他SELECT语句也是如此。
注:圆形功能只是做了规定长度数四舍五入,这是不负责获取特定格式的数据。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句