Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Little java thing wreckin me head

  • 01-12-2000 03:02PM
    #1
    Moderators, Education Moderators Posts: 1,699 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, Registered Users 2 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,699 Mod ✭✭✭✭Slaanesh


    Nice one ta.


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


    parseDouble is not a method in class Double.


  • Registered Users, Registered Users 2 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, Registered Users 2 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