Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2013
    Posts
    71
    Rep Power
    0

    Angry 2 doubles of same value does not euqal? whattt!!!!

    Java Code:
    double d1 = 0.5; double d2 = 0.1 + 0.1 + 0.1 + 0.1 + 0.1;
    		System.out.println("d1 and d2 are equal:"+ (d1 == d2));
    		//d1 and d2 are equal and i did expect this conclusion that they would be
    		double d3 = 0.3;
    		double d4 = 0.1 + 0.1 + 0.1;
    		System.out.println("d3 and d4 are equal:"+ (d3 == d4));
    		//d3 and d4 are not equal. i did not expect this at all. This was because???
    HOWWW???? WHY DOES .3 NOT EQUAL .1 + .1 + .1 when .5 equals .1 + .1 +.1 +.1 + .1??

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    25

    Default Re: 2 doubles of same value does not euqal? whattt!!!!

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: 2 doubles of same value does not euqal? whattt!!!!

    Before or after you read the recommended article, you might try printing out the values involved.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,423
    Blog Entries
    7
    Rep Power
    27

    Default Re: 2 doubles of same value does not euqal? whattt!!!!

    ...and print them out using the Double.toLongBits() method ...

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

Similar Threads

  1. using % with doubles plz explain
    By zazarath in forum New To Java
    Replies: 2
    Last Post: 03-10-2014, 01:15 AM
  2. Error getting doubles???
    By zubbylou in forum New To Java
    Replies: 2
    Last Post: 02-13-2014, 03:49 AM
  3. Add doubles in an array
    By maxiffer in forum New To Java
    Replies: 27
    Last Post: 01-20-2014, 02:39 PM
  4. Arithmetic using doubles
    By Black_Eye in forum New To Java
    Replies: 4
    Last Post: 10-19-2010, 08:35 AM
  5. Cant use doubles
    By Freakzoyd in forum New To Java
    Replies: 27
    Last Post: 07-24-2010, 04:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •