0

I have 2 textboxes on my form. The 1st takes input, which is then calculated to see if its value is between the for loop and then printed in the 2nd text box. I'm having trouble printing the value after the owed is calculated. I first converted the taxable variable to double and then I'm trying to print the owed in the second box but I can't find what I'm doing wrong. Does anyone have suggestions for what I'm doing wrong? Thanks.

private void btnCalculate_Click(object sender, EventArgs e)
{
    double taxable = Convert.ToDouble(txtTaxable.Text);
    double owed = Convert.ToDouble(txtOwed.Text);


    if (taxable > 0 && taxable < 100)
    {
        //once the owed is calculated I want it to print in
        // the txtOwed.Text
          owed = taxable * .1; 
        //txtOwed.Text = owed.ToString(txtIncome.Text);

    }
}
Reza Aghaei
  • 120,393
  • 18
  • 203
  • 398
  • 2
    Do not use double when doing _financial_ math. Use the decimal data type [decimal vs double](https://stackoverflow.com/questions/1165761/decimal-vs-double-which-one-should-i-use-and-when) – Steve Feb 07 '20 at 15:14

2 Answers2

0

You need to convert owed to a string and assign it to txtOwed.Text:

owed = taxable * .1; 
txtOwed.Text = owed.ToString();
ProgrammingLlama
  • 36,677
  • 7
  • 67
  • 86
0

Since you were able to convert the string into a double like so:

double owed = Convert.ToDouble(txtOwed.Text);

I suggest reversing that by converting your double into a string like so:

string temp = Convert.ToString(owed);

And then setting the textbox property like so:

txtOwed.Text = temp;
Freek W.
  • 406
  • 5
  • 20