我正在尝试计算汽车价格。 我试图获得汽车价格并将其转换为int,然后将int值乘以百分比,然后将结果显示在另一个文本框中。
这就是我所做的,它抛出异常:
private void button1_Click(object sender, EventArgs e)
{
int carPrice = Convert.ToInt32(txtCarPrice.Text);
carPrice = int.Parse(txtCarPrice.Text);
int downPayment = Convert.ToInt32(txtDownPayment.Text);
downPayment = int.Parse(txtDownPayment.Text);
downPayment = Convert.ToInt32(carPrice * .2);
txtDownPayment.Text = downPayment.ToString("0.#####");
}
它引发格式异常!