• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to read an int or double?

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all ;-)
Situation:
I'm writing an math application,and I need some fields in my GUI to enter the calculation params(lenght for example).
The TextField with getText method (you have explained me grately) returns a String;I need the method read a double or int from the field to use in aplication's further calculations.
How shall I do this?
And what about sending the result back to my window? (setText or drawText use Strings too)
Thank's very much.
 
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To make a double from a String:

To make an int:

 
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dominik
To get an int or double from a string you'd use one of the wrapper classes. Check out the Integer and Double classes in the java.lang.Number package. Both of these classes have methods that will take a String value and return a primitive. For example to get a double from a String you would do somehting like this:

After that code the variable dbl will have the primitive double value of 2.456
Hope that helps

------------------
Dave
Sun Certified Programmer for the Java� 2 Platform
reply
    Bookmark Topic Watch Topic
  • New Topic