Results 1 to 9 of 9
  1. #1
    Join Date
    Oct 2014
    Posts
    2
    Rep Power
    0

    Default Question about Doubles?

    Scanner scan = new Scanner(System.in);
    double val = scan.nextDouble();
    System.out.println(val - 11.5);

    Why is the output 56.397000000000000006 instead of 67.897?

    Thanks

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Question about Doubles?

    Hard to say without seeing the value in val.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    Join Date
    Oct 2014
    Posts
    2
    Rep Power
    0

    Default Re: Question about Doubles?

    Apologies. The value for val is 67.897.

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

    Default Re: Question about Doubles?

    Quote Originally Posted by Marquis de Faux View Post
    Apologies. The value for val is 67.897.
    I think you need to read your first post and restate the question.

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

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Question about Doubles?

    What is the value of 67.897 - 11.5?
    If you don't understand my response, don't ignore it, ask a question.

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: Question about Doubles?

    Please do not ask for code as refusal often offends.

    ** This space for rent **

  7. #7
    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: Question about Doubles?

    Can't we nail that link to the entrance of this forum? (together with the remark that you can't use == for object (String) equality comparison).

    kind regards,

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

  8. #8
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: Question about Doubles?

    NO DON'T!

    Nailing things to the entrance is a surefire way of making them completely invisible.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  9. #9
    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: Question about Doubles?

    Quote Originally Posted by gimbal2 View Post
    NO DON'T!

    Nailing things to the entrance is a surefire way of making them completely invisible.
    We could nail it to their forehead ...

    kindest 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
  •