-5

我无法弄清楚为什么代码格式错误。我得到了错误TotalTicketprice = decimal.Parse(overallTicketCostlabel.Text);以及与之相关的所有内容。有谁知道这个的解决方案?

private void calculateButton_Click(object sender, EventArgs e)
{
    int Tickets; //Quantity of Tickets
    decimal Price; //price per ticket
    decimal DiscountPercent = 0.1m; // Discount given
    decimal TotalTicketprice; //Ticket price before discount given
    decimal Discount;

    Tickets = int.Parse(ticketQuantityTextBox.Text);
    Price = decimal.Parse(priceTicketTextBox.Text);
    TotalTicketprice = decimal.Parse(overallTicketCostlabel.Text);
    Discount = decimal.Parse(initialDiscountLabel.Text);

    //Ticket Price
    overallTicketCostlabel.Text = (Price * Tickets).ToString("c");

    //Displays Discount
    initialDiscountLabel.Text = (TotalTicketprice * DiscountPercent).ToString("c");

    //Displays Discounted Total Cost
    discountedCostLabel.Text = (TotalTicketprice - Discount).ToString("c");
4

2 回答 2

3

根据您的命名约定,这只是一个猜测;

TotalTicketprice = decimal.Parse(overallTicketCostTextBox.Text);

代替:

TotalTicketprice = decimal.Parse(overallTicketCostlabel.Text);

您可能还希望在解析它们之前包含一些验证以确保它们是数字的。

于 2013-11-04T12:05:24.107 回答
0
 overallTicketCostlabel.Text = (Price * Tickets).ToString("c");

此格式为货币。这意味着它可能会在文本中包含货币符号。比如说$ 100

于 2013-11-04T12:08:39.180 回答