System.FormatException : Input string was not in a correct format ,on converting string to decimal.

后端 未结 4 1304
旧巷少年郎
旧巷少年郎 2021-01-05 11:51

I have a little problem with ASP.NET and C#. This is my error code:

An exception of type \'System.FormatException\' occurred in mscorlib.dll but was not

相关标签:
4条回答
  • 2021-01-05 12:08

    Please try with the below code snippet.

    CultureInfo info = CultureInfo.GetCultureInfo("es-ES");
    string storedValue = "3,85";
    decimal oldAmount;
    bool succes = Decimal.TryParse(storedValue, NumberStyles.Any, info, out oldAmount);
    
    0 讨论(0)
  • 2021-01-05 12:09

    Try using "0,85" instead of "0.85". I think you can use the dot decimal if you change culture. Here is some more information: How to change symbol for decimal point in double.ToString()?

    0 讨论(0)
  • 2021-01-05 12:20

    Use TextBox.Text instead:

    bool succes = Decimal.TryParse(TextBox.Text, out oldAmount);
    
    0 讨论(0)
  • 2021-01-05 12:30

    TextBox.value is wrong. YourTextBox.Text is correct...!

    bool success = Decimal.TryParse(TextBox.Text, out oldAmount);
    
    0 讨论(0)
提交回复
热议问题