adding and subtracting in double

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nischal Topno

    #1

    adding and subtracting in double

    public class Test {
    public static void main(String args[]) {
    double d1 = 20000.01;
    double d2 = 10000.01;
    double d3 = d1 - d2;
    System.out.prin tln(d3);
    }
    }

    why does the above code return 9999.9999999999 98.

    Is there any way to make it return 10000;

    Nischal
  • Ryan Stewart

    #2
    Re: adding and subtracting in double

    "Nischal Topno" <tnischal@yahoo .com> wrote in message
    news:5a72a007.0 408120125.3fdf0 f4e@posting.goo gle.com...[color=blue]
    > public class Test {
    > public static void main(String args[]) {
    > double d1 = 20000.01;
    > double d2 = 10000.01;
    > double d3 = d1 - d2;
    > System.out.prin tln(d3);
    > }
    > }
    >
    > why does the above code return 9999.9999999999 98.
    >
    > Is there any way to make it return 10000;
    >[/color]
    Yes. Round it. See



    Comment

    Working...