我的问题是它只接受12345.如果它是12,345,它没有显示或它没有被program.it读取。但是没有错误。
这是我的代码:
private void UpdateTotalBill()
{
decimal vat = 0;
decimal TotalPrice = 0;
long TotalProducts = 0;
foreach (DataListItem item in dlCartProducts.Items)
{
Label PriceLabel = item.FindControl("lblPrice") as Label; // get price
TextBox ProductQuantity = item.FindControl("txtProductQuantity") as TextBox; // get quantity
Int64 priceLabel, productQuantity;
bool conversionResult = Int64.TryParse(PriceLabel.Text, out priceLabel);
if (!conversionResult) continue;
conversionResult = Int64.TryParse(ProductQuantity.Text, out productQuantity);
if (!conversionResult) continue;
decimal ProductPrice = priceLabel * productQuantity; //computation fro product price. price * quantity
vat = (TotalPrice + ProductPrice) * 0.12M; // computation for vat
vat = Math.Round(vat, 2);
TotalPrice = TotalPrice + ProductPrice;
TotalProducts = TotalProducts + productQuantity;
}
Label1.Text = Convert.ToDecimal(vat).ToString("#,##0.00");
txtTotalPrice.Text = Convert.ToDecimal(TotalPrice + 40.0M + vat).ToString("#,##0.00"); // add vat + 40 delivery charge to total price
txtTotalProducts.Text = Convert.ToString(TotalProducts);
btnIslandGas.Text = Convert.ToString(TotalProducts);
}
无法读取的值与产品价格有关。当值没有逗号时,程序将读取它。当它有逗号(12,345)时,它没有被阅读或显示。对此有什么诡计吗?