Converting .Text to double in C# .net

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • help1267
    New Member
    • Aug 2006
    • 10

    Converting .Text to double in C# .net

    I'm trying to convert an entry from a form text box to a double and am always getting "Input string was not in the correct format".

    This is my code:

    dblAmount = double.Parse(fr m_aTest.txtAmou nt.Text);

    If I hardcode:

    dblAmount = double.Parse("1 0000");

    it works

    I'm using C# .net
  • Lok
    New Member
    • Nov 2006
    • 11

    #2
    Originally posted by help1267
    I'm trying to convert an entry from a form text box to a double and am always getting "Input string was not in the correct format".

    This is my code:

    dblAmount = double.Parse(fr m_aTest.txtAmou nt.Text);

    If I hardcode:

    dblAmount = double.Parse("1 0000");

    it works

    I'm using C# .net
    Yes, both should work ok. But maybe it's because the overall logic flow. eg. the above line executed before the user entered the text, etc.

    Maybe a code snippet will help us to diagnose more.

    regards,

    Lok

    Comment

    • nmsreddi
      Contributor
      • Jul 2006
      • 366

      #3
      hello

      what you have done is exactly correct ,its working fine at my side

      be sure your text box name you are using is correct and it is server side control


      try it

      Comment

      • MengChee
        New Member
        • Aug 2010
        • 4

        #4
        how to convert textbox data into double?
        if (GPSLong.Text != null)
        {
        lg = Double.Parse(GP SLong.Text);

        }
        else
        {
        lg = 101.152496;
        }
        if the text box value is null but when debug said that have error on the "lg = Double.Parse(GP SLong.Text);"
        ("Input string was not in a correct format)

        Comment

        Working...