Jump to content

how to read float?Netbeans GUI

- - - - -

  • Please log in to reply
2 replies to this topic

#1
alex1

alex1

    Learning Programmer

  • Members
  • PipPipPip
  • 93 posts
Hello guys! I'm new to java.I'm trying to make a program wich is somthing like a rstaurant DB...I'm going well,but I have a problem.In few cases I have to read a float and I have no idea how to do this...I mean,I managed to convert the string from a text box to integer,but idk how to do this for a float.
Here is an example:

private void addProductActionPerformed(java.awt.event.ActionEvent evt) {                                           

       Products temp=new Products(tfProdName.getText(),Integer.parseInt(txtID.getText()));

       products.add(temp);

    }                                


As you can see I have managed to convert the text to integer using:

Integer.parseInt(txtID.getText());


Is it a way to convert the text to float,or I just have to use another container type? If yes,what container should I use?

Any help is highly appreciated!!! :)

#2
gregwarner

gregwarner

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 853 posts
  • Location:Arkansas
Like this:

Float.parseFloat(string);

You can do this with any of the Java primitive wrapper classes.
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.

– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid


#3
alex1

alex1

    Learning Programmer

  • Members
  • PipPipPip
  • 93 posts
THANK YOU!!!!!!!!!!!!!!!!!
You realy helped me A LOT!!!!!

Thanks again!! :)




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users