Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting double to string and back again? 1

Status
Not open for further replies.

DeanConsulting

Programmer
Jan 11, 2002
131
US
I am a Java newbie and I know that I have a simple question that someone can help me with. I just cannot find the solution on my own.

How does one convert double to string and string to double? I cannot seem to figure out how to do this. Is there a cast for it?

Thanks in advance.
Noble


---------------------------------------
Noble D. Bell
 
Euh ... String to double ??
A String can contains hundreds of characters. How do u want to convert it in 8 bytes ?

U mean long -> char and char -> long no ?
 
What I mean is this:

I am doing a calculator project.


I have two variables that are type double.

I want to be able to add, subtract, multiply, or divide by the user entering numbers in via keypad or mouse

I need to take results and display them in the calculator display.

ie. jTextField

I hope this is more understandable than my last post. Sorry.

Noble



---------------------------------------
Noble D. Bell
 
If you're dealing with a primitive type double :

Code:
double dVal = 1.0d;
String sVal = dVal +"";
double dNewVal = 0.0d;
try { 
  dNewVal = Double.parseDouble(sVal);
} catch (NumberFormatException npe) {
  // handle error
}

--------------------------------------------------
Free Database Connection Pooling Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top