loy*_*pek 0 c# sql-server-2008
每当我在我的TextBox中放置值时,我希望我的输出不会被舍入.例如5000/2000我想要显示的输出是2,但它显示3.
这是我的代码
private void InsertReceipt()
{
decimal Stub;
Stub = decimal.Parse(txtAmount.Text) / 2000;
SqlCommand cmd = new SqlCommand();
cmd.Connection = cn;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "INSERT INTO Ticket(CustomerID, Date, Store, Amount, NoStub)" + "VALUES (@CustomerID, @Date, @Store, @Amount, @NoStub) ";
cmd.Parameters.AddWithValue("@CustomerID", txtCustomerID.Text);
cmd.Parameters.AddWithValue("@Date", dtpDate.Value.Date.ToString());
cmd.Parameters.AddWithValue("@Store", txtStore.Text);
decimal amount = decimal.Parse(txtAmount.Text);
cmd.Parameters.AddWithValue("@Amount", amount);
cmd.Parameters.Add("@NoStub", SqlDbType.Decimal).Value = Stub;
cmd.ExecuteNonQuery();
}
Run Code Online (Sandbox Code Playgroud)
小智 6
我认为Math.Floor就是你要找的东西:
Stub = Math.Floor(decimal.Parse(txtAmount.Text) / 2000);
Run Code Online (Sandbox Code Playgroud)
Floor()总是向下舍入.
| 归档时间: |
|
| 查看次数: |
302 次 |
| 最近记录: |