Java minus value parsing error

Discussion in 'Java' started by Saehoon, Nov 4, 2006.

  1. Saehoon

    Saehoon Guest

    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?
     
    Saehoon, Nov 4, 2006
    #1
    1. Advertising

  2. Saehoon

    Lee Weiner Guest

    In article <>, "Saehoon"
    <> wrote:
    >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
     
    Lee Weiner, Nov 4, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. mm
    Replies:
    1
    Views:
    6,144
  2. =?Utf-8?B?Q2hyaXM=?=

    getfiles, minus the path?

    =?Utf-8?B?Q2hyaXM=?=, Dec 29, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    518
    Ken Cox [Microsoft MVP]
    Dec 30, 2004
  3. =?Utf-8?B?QXNoYQ==?=

    how to minus a date?

    =?Utf-8?B?QXNoYQ==?=, Jan 18, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    10,050
    Juan T. Llibre
    Jan 18, 2005
  4. rdaly
    Replies:
    0
    Views:
    480
    rdaly
    Jun 21, 2006
  5. Ciaran
    Replies:
    21
    Views:
    11,735
    dorayme
    Mar 24, 2010
Loading...

Share This Page