Java minus value parsing error

S

Saehoon

Hi guys,
I'd like to parse the String to double value.
But String has a minus value such as "-1", "-2"...
I used the Double.parseDouble(String s); method.

The example code is

String s = "-1";
double d = Double.parseDouble(s);

This doesn't seem to work properly.
How can I correctly parse the minus value?
 
L

Lee Weiner

"Saehoon" said:
Hi guys,
I'd like to parse the String to double value.
But String has a minus value such as "-1", "-2"...
I used the Double.parseDouble(String s); method.

The example code is

String s = "-1";
double d = Double.parseDouble(s);

This doesn't seem to work properly.
How can I correctly parse the minus value?

What do you mean, it doesn't seem to work properly?
It works perfectly for me.

public class ParseDouble
{
public static void main( String[] args )
{
String s = "-1";
double d = Double.parseDouble( s );
System.out.println( d );
}
}

Displays -1.0

Lee Weiner
lee AT leeweiner DOT org
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top