Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Little java thing wreckin me head

Options
  • 01-12-2000 3:02pm
    #1
    Moderators, Education Moderators Posts: 1,863 Mod ✭✭✭✭


    Dont get to ask how this is done till Monday so I thought I would ask here.

    When getting data in from a textfield how do you recieve it as a double ?
    Eg. 4.3 rather than an integer of just 4.

    Slaan


Comments

  • Closed Accounts Posts: 1,651 ✭✭✭Enygma


    Look up 'casting'


  • Registered Users Posts: 1,481 ✭✭✭satchmo


    Double.parseDouble(String) should do the trick, ie:
    double d=Double.parseDouble(t.getText());
    

    where t is the TextField.


  • Moderators, Education Moderators Posts: 1,863 Mod ✭✭✭✭Slaanesh


    Nice one ta.


  • Moderators, Education Moderators Posts: 1,863 Mod ✭✭✭✭Slaanesh


    parseDouble is not a method in class Double.


  • Registered Users Posts: 1,481 ✭✭✭satchmo


    Yes it is...
    What JDK version are you using?

    I'm using 1.3 and I just tried this program:
    class testdouble{
    	public static void main(String args[]){
    		double d=Double.parseDouble("4.3");
    		System.out.println(d);
    	}
    }
    

    and it compiled and ran fine for me.


  • Advertisement
  • Registered Users Posts: 1,481 ✭✭✭satchmo


    I looked it up and parseDouble has only been in JDK since v1.2, so if you're still using an earlier version then you'll need to get a newer one.

    If you are using v1.2 or above then you might try importing java.lang.Double at the top of your program, although you shouldn't need to.

    Alternatively, this should work in any version:
    double d=(new Double("4.3")).doubleValue();
    


Advertisement