-2
double buy, sell, qt, tsell, tbuy, trev;
private void pro_cal()
{
    sell = Convert.ToDouble(edt_sell.Text);
    buy = Convert.ToDouble(edt_buy.Text);
    qt = Convert.ToDouble(edt_qt.Value);
    tsell = sell * qt;
    tbuy = buy * qt;
    trev = tsell - tbuy;
    lblTbuy.Text = tbuy.ToString();
    lblTsell.Text = tsell.ToString();
    lblTRev.Text = trev.ToString();
}

I tried double.tryparse but that doesn't work.

when I empty out my textbox here is what I get!

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • 2
    `double.TryParse()` does *work*. *Try* again. – Jimi Jun 18 '22 at 18:12
  • 1
    You can also use NumericUpDown Controls or test the content of your TextBoxes beforehand. -- You should avoid `Convert.ToSomething()` anyway. – Jimi Jun 18 '22 at 18:17
  • Obviously, the content of the `edt_buy` input cannot be parsed to a double. And what do you mean by `double.TryParse` doesn't work. It works perfectly fine if you use it correctly. – derpirscher Jun 18 '22 at 18:20

1 Answers1

0

I'm not able to comment yet so I'll do it here: please, show us the string you're typing

Maybe the string has a space to you could use Trim() to remove them

However, what I think is the most probably thing, is that the method is trying to parse it with another internationalization. For example, we use our number like 3,100.82 where the comma is to distinguish between thousands, millions or billions and the dot is to distinguish decimals, however, in other countries they write the numbers like 3.100,82... it's exactly the opposite.

To solve that, you have to add the culture info to the method, like this:

buy = Convert.ToDouble(edt_buy.Text, NumberStyles.AllowDecimalPoint, CultureInfo.CurrentCulture);

That may work, but please add to your post how you wrote the number since I may be wrong