1
JTextField text=new JTextField();
text.gettext();

//I want text.gettext(); value to be a float value to calculate a problem . How to take it as ??

  • 1
    check out the [`Double`](http://docs.oracle.com/javase/8/docs/api/java/lang/Double.html) class, you might find something there – ajb Aug 10 '16 at 04:08
  • 1
    He would rather check the Float class as he askes for that not for Double. Also this might be duplicate of String to float parsing – Andreas Brunnet Aug 10 '16 at 04:10
  • 1
    If your question is _not_ a duplicate, please edit your question to include a [mcve] that shows your current approach and describe nay problems you encounter. – trashgod Aug 10 '16 at 04:27

1 Answers1

2

In order to read a float from a text field you can do it two ways.

String a=text.getText();//Create a string to store the incoming data
float f = Float.parseFloat(a);// to cast the data

Else

float f = Float.parseFloat(text.getText);
Jayavignesh Vicky
  • 2,166
  • 1
  • 13
  • 15