POS (Point Of Sale)를 만들고 있는데 가격 " 0.60
"을 정수 로 변환하려고 할 때 문제가 발생했습니다 .
데이터 배경 : 데이터 소스에 대한 모든 데이터는 내가 설정하고 문제없이 연결 한 MySQL 데이터베이스에서 가져온 것입니다.
가격은 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)
이 문제를 해결하기 위해 설정 을 사용하려고 시도했지만 내가 살펴본 내용을 볼 수 없습니다. 0.60
가능한 한 내 DataGridView-DGVIIL에 가격을 표시하고 싶습니다 .
0.60
정수가 아닙니다. 오류가 바로
대안 :
Decimal d = Decimal.Parse(txtPrice.Text);
또는 더 나은 :
Decimal d;
if ( decimal.TryParse(txtPrice.Text, out d) == false ){
//handle bad number...
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다