-3
    private void tbnRaknaMoms_Click(object sender, EventArgs e)
    {
        MessageBox.Show(ToPercentage().ToString());
    }
    public float ToPercentage()
    {
        float varde = float.Parse(tbxInput.Text);
        float result = 100 * varde;
        return result;
    }   

I want to make a method that counts the tax. When I run this I get an error :

An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll.

venerik
  • 5,766
  • 2
  • 33
  • 43
Alex
  • 39
  • 3
  • 5

1 Answers1

0

The problem is that the input is parsed according to the CultureInfo of the local computer. If you want to have the same "default" decimal delimiter, use this:

 float value = float.Parse(tbxInput.Text, CultureInfo.InvariantCulture);
Philippe Paré
  • 4,279
  • 5
  • 36
  • 56