jackofblaze
jackofblaze

Reputation: 37

Trouble Converting String to Double

I'm trying to make it so that when a button is clicked it takes strings from two text boxes and converts them to doubles. However, every time I try to debug it, upon clicking the button the compiler tells me "input string was not in a correct format." I'm not really sure why it isn't working. Here's the code for the button click:

protected void btnCalculateSalary_Click(object sender, EventArgs e)
{
    double annualHours = 0.0;
    double payRate = 0.0;
    double annualSalary = 0.0;

    annualHours = Convert.ToDouble(lblAnnualHours.Text);
    payRate = Convert.ToDouble(lblPayRate.Text);

    annualSalary = annualHours * payRate;

    lblAnnualSalary.Text = "Annual Salary: $" + annualSalary.ToString("C");
}

Upvotes: 0

Views: 62

Answers (1)

Flotto
Flotto

Reputation: 183

Are you maybe trying to parse the texts of the labels instead of the textboxe`s texts? The names lblAnnualHours and lblPayRate indicate that.

Upvotes: 2

Related Questions