Changing data type of textbox?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kjkrudh
    New Member
    • Sep 2007
    • 9

    Changing data type of textbox?

    How do I convert text (String) from a textbox to a float. I have a user textbox that is entering a number. It is entering as a String. Need it to be a float.
  • nickyeng
    Contributor
    • Nov 2006
    • 252

    #2
    Originally posted by kjkrudh
    How do I convert text (String) from a textbox to a float. I have a user textbox that is entering a number. It is entering as a String. Need it to be a float.
    Code:
    try{
        float f1 = Float.parseFloat(str);
    }
    catch(NumberFormatException nfe) { 
       // catch the exception if the String entered is not numeric values.
    }
    it convert String to float.

    from
    Nick

    Comment

    • kjkrudh
      New Member
      • Sep 2007
      • 9

      #3
      Still very confused.
      I need to get from the txtGPA (name of my textbox), and store it as a float in my array.

      I'm new to Java so any help is appreciated.

      Comment

      • nickyeng
        Contributor
        • Nov 2006
        • 252

        #4
        Code:
        float[] arr = new float[3];
        // use the method to get the value of textbox and parse to float
        float[0] = Float.parseFloat(textGPA.getValue());
        something like that...

        Comment

        • vipinkrajput
          New Member
          • Sep 2007
          • 5

          #5
          Originally posted by kjkrudh
          How do I convert text (String) from a textbox to a float. I have a user textbox that is entering a number. It is entering as a String. Need it to be a float.

          float floatValue = Float.parseFloa t(txtGPA.getTex t());



          parseFloat(Stri ng str) is the static method of class Float

          Comment

          • kjkrudh
            New Member
            • Sep 2007
            • 9

            #6
            Originally posted by vipinkrajput
            float floatValue = Float.parseFloa t(txtGPA.getTex t());



            parseFloat(Stri ng str) is the static method of class Float


            Thank you so much! That all worked great.

            Comment

            Working...