我数据库中有个字段是decimal(8,2)类型 长度8,精度2
我在c#中要通过存储过程把它读出来(输出参数)
com.Parameters.Add("@price", SqlDbType.Decimal); com是SqlCommand对象
如果数据库中价格是15.55 那么读出来在c#中就是16 也就是怎么在c#中限制这个decimal的精度 使在c#中读出来和数据库中是一致的下面是全部代码:
using( SqlConnection sqlConn = new SqlConnection() )
{
sqlConn.ConnectionString = "server=(local);database=myDataBase;uid=sa;pwd=";
sqlConn.Open();
SqlCommand com = new SqlCommand("pd_GetBookPrice");
com.Connection = sqlConn;
com.CommandType = CommandType.StoredProcedure; com.Parameters.Add("@id", SqlDbType.Int);
com.Parameters["@id"].Value = 1; com.Parameters.Add("@price", SqlDbType.Decimal);
com.Parameters["@price"].Direction = ParameterDirection.Output;
com.ExecuteNonQuery(); label3.Text = com.Parameters["@price"].SqlValue.ToString();
/////这里打印出来 如果数据库中是15.55 那么就变成16 sqlConn.Close();
}
我在c#中要通过存储过程把它读出来(输出参数)
com.Parameters.Add("@price", SqlDbType.Decimal); com是SqlCommand对象
如果数据库中价格是15.55 那么读出来在c#中就是16 也就是怎么在c#中限制这个decimal的精度 使在c#中读出来和数据库中是一致的下面是全部代码:
using( SqlConnection sqlConn = new SqlConnection() )
{
sqlConn.ConnectionString = "server=(local);database=myDataBase;uid=sa;pwd=";
sqlConn.Open();
SqlCommand com = new SqlCommand("pd_GetBookPrice");
com.Connection = sqlConn;
com.CommandType = CommandType.StoredProcedure; com.Parameters.Add("@id", SqlDbType.Int);
com.Parameters["@id"].Value = 1; com.Parameters.Add("@price", SqlDbType.Decimal);
com.Parameters["@price"].Direction = ParameterDirection.Output;
com.ExecuteNonQuery(); label3.Text = com.Parameters["@price"].SqlValue.ToString();
/////这里打印出来 如果数据库中是15.55 那么就变成16 sqlConn.Close();
}
试试
http://www.cnblogs.com/enuosky/archive/2006/07/21/456206.html
Problem 1002: Big Decimal Addition
http://www.cnblogs.com/NickyYe/archive/2007/02/06/642508.html