我的程序没有正确保存数字 [英] My program is not saving numbers correctly
本文介绍了我的程序没有正确保存数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我从文本框(txtMaterialUnitPrice,txtMaterialUnitPrice)(例如4,5和6,5)输入十进制数字时,总价应为29,25,但它为29.这是我的代码.
When I enter decimal numbers from textboxes(txtMaterialUnitPrice,txtMaterialUnitPrice) like 4,5 and 6,5 the total price should come 29,25 but it comes 29. Here is my code.
private void btnSale_Click(object sender, EventArgs e)
{
salesTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
materialPrice = Decimal.Parse(txtMaterialUnitPrice.Text);
purchasedWeight = Decimal.Parse(txtMaterialUnitPrice.Text);
totalPrice = materialPrice * purchasedWeight;
curSales = Sales.Insert(customerID, customerNameSurname, customerPlate, materialID, materialType, materialPrice, purchasedWeight, totalPrice, salesTime, txtExplanation.Text);
LoadAll();
}
这是插入部分.
public static Sales Insert(int cID, String cNameSurname, String cPlate, int mID, String mName, Decimal mPrice, Decimal pWeight, Decimal totalPrice, String dt, String explanation)
{
String query = string.Format("INSERT INTO sales(CustomerID,CustomerNameSurname,CustomerPlate,MaterialID,MaterialType,MaterialPrice,PurchasedWeight,TotalPrice,SalesDate,Explanation) VALUES ('{0}', '{1}' , '{2}', '{3}','{4}','{5}','{6}','{7}','{8}','{9}')", cID, cNameSurname, cPlate, mID, mName, mPrice, pWeight, cleanAmount, dt, explanation);
MySqlCommand cmd = new MySqlCommand(query, DB.dbConn);
DB.dbConn.Open();
cmd.ExecuteNonQuery();
int id = (int)cmd.LastInsertedId;
Sales sale = new Sales(id, cID, cNameSurname, cPlate, mID, mName, mPrice, pWeight, totalPrice, dt, explanation);
DB.dbConn.Close();
return sale;
}
推荐答案
解决方案中的问题是,"符号.C#中的逗号是您使用."的十进制值.标志就是为什么将其组合
The problem in your solution is the "," sign. The comma in C# the decimal value you use the "." sign that is why it combines it
//示例//这将起作用
//Example //This will work
十进制测试= 7.5;
decimal test = 7.5;
//这不起作用
十进制测试= 7.5;
decimal test = 7,5;
更改小数点指针符号
这篇关于我的程序没有正确保存数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文