POS (販売時点管理) を作成していますが、価格 " 0.60
" を整数に変換しようとしたときに問題が発生しました。
データの背景: データ ソースのすべてのデータは、セットアップして問題なく接続した MySQL データベースからのものです。
Price は TextBox に格納され、" 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)
見落としていたものがわかりません。可能であれば、Price を DataGridView - DGVIIL に表示したいと思います0.60
。