Why does multiplying a double by -1 not give the negative of the current answer

Posted by Ankur on Stack Overflow See other posts from Stack Overflow or by Ankur
Published on 2010-03-18T08:32:32Z Indexed on 2010/03/18 8:41 UTC
Read the original article Hit count: 357

I am trying to multiply a double value by -1 to get the negative value. It continues to give me a positive value

    double man = Double.parseDouble(mantissa);
    double exp;
    if(sign.equals("plus")){
        exp = Double.parseDouble(exponent);
    }
    else {
        exp = Double.parseDouble(exponent);
        exp = exp*-1;
    }


    System.out.println(man+" - "+sign+" - "+exp);

The printed result is

13.93 - minus - 2.0

which is correct except that 2.0 should be -2.0

© Stack Overflow or respective owner

Related posts about java

Related posts about double