none
input string was not in a correct format RRS feed

  • Question

  • Hi,

    My code is like this where i am converting a text box value to float ,but i am getting input string was not in correct format error.

    plz fix this.

         float fltVolt = float.Parse(DEVtxtLVNomianlVoltage.Text)

    Thursday, November 22, 2012 2:39 PM

Answers

  • Hi,

    you can use float.TryParse method to not raise any exception in case user provides invalid entry .In that case you can check the returned value from this function and if that is false it means conversion was falied and you can put some custom message thereafter .

    float f;

    bool res = float.TryParse(TextBox1.Text,out f);


    One good question is equivalent to ten best answers.

    Tuesday, November 27, 2012 7:11 AM

All replies

  • Hi ramakanta,

    Make sure that DEVtxtLVNomianlVoltage Text box should not contains any characters or symbols.

    Try as below:

    string str = "2.354";
    float flt = float.Parse(str);




    PS.Shakeer Hussain


    Thursday, November 22, 2012 3:02 PM
  • Hi,

    you can use float.TryParse method to not raise any exception in case user provides invalid entry .In that case you can check the returned value from this function and if that is false it means conversion was falied and you can put some custom message thereafter .

    float f;

    bool res = float.TryParse(TextBox1.Text,out f);


    One good question is equivalent to ten best answers.

    Tuesday, November 27, 2012 7:11 AM