0

I have a form with a button that adds the values of multiple labels(that are filled with currency values) and displays the sum in another label.

decimal[] totals = new decimal[11]; 

    private void calculate_Click(object sender, EventArgs e)
    {
        totals[0] = decimal.Parse(lblText1.Text, NumberStyles.Currency);
        totals[1] = decimal.Parse(lbltext2.Text, NumberStyles.Currency);
        lbltotal.Text = totals.Sum().ToString("C");
    }

Works fine until one is empty and I get 'input string not in a correct format'.

1
  • 2
    what do you expect? what should be decimal value for ""? Commented Mar 13, 2013 at 15:36

1 Answer 1

1
  1. Don't bother calling if the text is empty
  2. Use decimal.TryParse
Sign up to request clarification or add additional context in comments.

1 Comment

When I input the arguments for TryParse I get 'cannot implicitly convert type 'bool' to 'decimal'.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.