String转换为int和int转换为String c#

时间:2015-11-19 04:40:30

标签: c#

我正在尝试计算汽车价格。 我试图获得汽车价格并将其转换为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.#####");
}

它引发格式异常!

0 个答案:

没有答案