Welcome to Dream.In.Code
Become a Java Expert!

Join 150,381 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,373 people online right now. Registration is fast and FREE... Join Now!




How to convert a variable from String to a double

 
Reply to this topicStart new topic

How to convert a variable from String to a double

michael351
5 Feb, 2008 - 08:34 PM
Post #1

New D.I.C Head
*

Joined: 29 Jan, 2008
Posts: 12

Hi all,

Whats the code for converting a string to a double?

The code to converting a string to a integer is

int dob = Integer.parseInt(dobStr);

where dob is the variable and dobStr aswell efcourse.


User is offlineProfile CardPM
+Quote Post

dontKnowJava
RE: How To Convert A Variable From String To A Double
5 Feb, 2008 - 08:47 PM
Post #2

D.I.C Head
**

Joined: 29 Sep, 2007
Posts: 213


My Contributions
well simply follow the logic if int dob = Integer.parseInt(dobStr); converts a string to int then double d = Double.parseDouble(dobStr); would convert a string to double
User is offlineProfile CardPM
+Quote Post

bhandari
RE: How To Convert A Variable From String To A Double
6 Feb, 2008 - 12:09 AM
Post #3

D.I.C Addict
Group Icon

Joined: 31 Jan, 2008
Posts: 747


Dream Kudos: 900
My Contributions
Just for information:

String.valueOf(Double d) for converting double to string
User is offlineProfile CardPM
+Quote Post

PennyBoki
RE: How To Convert A Variable From String To A Double
6 Feb, 2008 - 05:07 AM
Post #4

system("revolution");
Group Icon

Joined: 11 Dec, 2006
Posts: 2,011



Thanked: 7 times
Dream Kudos: 500
Expert In: Java,C++,C

My Contributions
QUOTE(bhandari @ 6 Feb, 2008 - 01:09 AM) *

Just for information:

String.valueOf(Double d) for converting double to string

Just to clarify that. That function takes String as a parameter and returns Double.
User is offlineProfile CardPM
+Quote Post

1lacca
RE: How To Convert A Variable From String To A Double
6 Feb, 2008 - 05:53 AM
Post #5

code.rascal
Group Icon

Joined: 11 Aug, 2005
Posts: 3,822



Thanked: 12 times
My Contributions
My eyes are rolling here, you are both correct, but it took me a while to find out what the last two posts were meant to be. So to share it:
Penny is referring to the OP, not the function bhandri posted
bhandri posted for the sake of education the opposite of the OP, that would reverse the process: converts a double to a String. Actually the function
QUOTE
String.valueOf(Double d) for converting double to string
does not exists, I think he meant String String.valueOf(double d).

User is offlineProfile CardPM
+Quote Post

bhandari
RE: How To Convert A Variable From String To A Double
6 Feb, 2008 - 08:14 AM
Post #6

D.I.C Addict
Group Icon

Joined: 31 Jan, 2008
Posts: 747


Dream Kudos: 900
My Contributions
QUOTE
String String.valueOf(double d).



Thanx for the full signature.
User is offlineProfile CardPM
+Quote Post

dontKnowJava
RE: How To Convert A Variable From String To A Double
6 Feb, 2008 - 08:22 AM
Post #7

D.I.C Head
**

Joined: 29 Sep, 2007
Posts: 213


My Contributions
hold on you got me all confused how does String.valueOf(Double d) that take a string and convert it to double? i thing its the other way around. and what 1lacca said y do u say there is no such method String.valueOf(Double d)? its in the java docs
User is offlineProfile CardPM
+Quote Post

1lacca
RE: How To Convert A Variable From String To A Double
6 Feb, 2008 - 08:39 AM
Post #8

code.rascal
Group Icon

Joined: 11 Aug, 2005
Posts: 3,822



Thanked: 12 times
My Contributions
QUOTE(dontKnowJava @ 6 Feb, 2008 - 05:22 PM) *

hold on you got me all confused how does String.valueOf(Double d) that take a string and convert it to double? i thing its the other way around.

Yes, it takes a double (and not a Double) and converts it to a String. (nobody said it otherwise)

QUOTE(dontKnowJava @ 6 Feb, 2008 - 05:22 PM) *

and what 1lacca said y do u say there is no such method String.valueOf(Double d)? its in the java docs

String.valueOf(Double d) is not in the Javadoc, it's String.valueOf(double d) what you can find there: it takes a primitive type not the wrapper object (however auto boxing might get over such a problem)

QUOTE
Thanx for the full signature.

Not the full sig, I posted it because of the aforementioned Double != double problem.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 03:41PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month