Results 1 to 6 of 6
  1. #1
    hqt
    hqt is offline Member
    Join Date
    Nov 2011
    Posts
    27
    Rep Power
    0

    Question Boolean: different two type of declare

    I have 2 examples, I don't know what java really acts:
    Java Code:
    boolean x = 4.45f==4.45;
    boolean y=4.44f==4.44;
    Java will turn that (x=true) and (y=false). So, please tell me what java do in 2 above statements, please.

    thanks :)

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,015
    Blog Entries
    7
    Rep Power
    20

    Default Re: Boolean: different two type of declare

    Those boolean results imply that the float and double representations for 4.45 are identical while a float value 4.44 cast to type double differs from a double type value 4.45. Read this article.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    hqt
    hqt is offline Member
    Join Date
    Nov 2011
    Posts
    27
    Rep Power
    0

    Default Re: Boolean: different two type of declare

    @: JosAH, thank for your kindly help. But can you tell me more shortly, please. I think this problem come from what java work. Because in C/C++, above code will output false for two case, too :D
    @:I don't like your document you give to me, not because it's long, or not because it's hard. I don't like it because: It's long, and many part of this document seem easy to me (maybe because It belongs to math, and I love it). So, I hard to find what I need :(

    thanks :)

  4. #4
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

    Default Re: Boolean: different two type of declare

    He did tell you, it has to do with java's float and double representations. Read that document, completely, and you will understand.

  5. #5
    hqt
    hqt is offline Member
    Join Date
    Nov 2011
    Posts
    27
    Rep Power
    0

    Default Re: Boolean: different two type of declare

    He did tell you, it has to do with java's float and double representations. Read that document, completely, and you will understand.
    Oh, so thank for your help :P

  6. #6
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

    Default Re: Boolean: different two type of declare

    I see no reason why we should repeat (with less accuracy and detail) what is already contained in the document (that you have). Just read it.

Similar Threads

  1. Replies: 3
    Last Post: 11-18-2011, 08:15 AM
  2. Boolean Data type
    By maya700 in forum New To Java
    Replies: 8
    Last Post: 05-04-2011, 03:38 PM
  3. Declare INTEGER expecting/requiring BOOLEAN
    By mine0926 in forum NetBeans
    Replies: 4
    Last Post: 04-30-2010, 01:44 AM
  4. declare class data member as an inteface type
    By everurz in forum Advanced Java
    Replies: 3
    Last Post: 12-21-2009, 01:04 PM
  5. Replies: 1
    Last Post: 12-09-2009, 12:57 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
  •