我正在创建一个 POS(销售点),但在尝试将价格“ 0.60
”转换为整数时遇到了问题。
数据背景:数据源的所有数据都来自我已经设置并连接没有问题的 MySQL 数据库。
价格存储在一个文本框中并被格式化为“ 0.60
”,我相信这就是它没有被转换的原因。我不断收到下面的消息。
附加信息:输入字符串的格式不正确。
//Puts the Price Into a String.
string NewPrice = txtPrice.Text;
//Converts The Quantity In the TextBox field to a numbers.
Quantity = Convert.ToInt32(txtQuant.Text);
//Incorrect Format & Attempt One.
//Price = Convert.ToInt32(NewPrice); <--- Problem.
//Price = int.Parse(NewPrice);
// I've also tried this method below with two '0' inside the { } brackets.
// But Still No Luck.
Price = Convert.ToInt32(string.Format("{0.00}",txtPrice.Text)); // <--- Problem.
// Times Price & Quantity to get Total Price (0.60 * 2 = 1.20)
TotalSingleItemPrice = Price * Quantity;
// The Single Item Price is added into the overall total.
TotalPrice += TotalSingleItemPrice;
// Converts Total Item Price to String from Int.
string TotalPriceStr = Convert.ToString(TotalSingleItemPrice);
// Puts TextBoxes / Strings Into One String array (I think).
string[] InizialItemList = new string[] { cmboInitItem.Text, Convert.ToString(Price), Convert.ToString(Quantity), TotalPriceStr};
// Adds The String Array Into the Data Grid View.
DGVIIL.Rows.Add(InizialItemList);
我试图使用string.Format("{0.00}",txtPrice.Text)
设置来解决这个问题,我只是看不到我看过的东西。我希望价格尽可能出现在我的 DataGridView - DGVIIL 中0.60
。