Results 1 to 8 of 8
Like Tree4Likes
  • 4 Post By noctarius

Thread: I don't understand what the difference is between a float and a double

  1. #1
    psx2514 is offline Member
    Join Date
    Oct 2012
    Posts
    50
    Rep Power
    0

    Default I don't understand what the difference is between a float and a double

    Whenever I look this up, the explanation I get seems to be convoluted to me, and I can't get a simple straight answer. So, to be more specific, could someone explain to me, for example what the difference between double a = 2.25 and float a = 2.25f is? Also, when is it more appropriate to use a float over a double, and vice versa (I'm looking for specific examples if possible)?

    Also, I don't know if this is related to this question or not, but how do you get a program to NOT truncate a zero at the end of a decimal. For example, I want to program to output 0.50 instead of 0.5

  2. #2
    killutch is offline Member
    Join Date
    Sep 2012
    Posts
    70
    Rep Power
    0

    Default Re: I don't understand what the difference is between a float and a double

    double can hold more numbers

    float = 32-bit
    double = 64-bit

    with primitives you are limited in how much can be held because it reserves the space on the machine and doesn't change.

  3. #3
    psx2514 is offline Member
    Join Date
    Oct 2012
    Posts
    50
    Rep Power
    0

    Default Re: I don't understand what the difference is between a float and a double

    Quote Originally Posted by killutch View Post
    double can hold more numbers

    float = 32-bit
    double = 64-bit

    with primitives you are limited in how much can be held because it reserves the space on the machine and doesn't change.
    I know that, but that doesn't really answer my question.

  4. #4
    noctarius is offline Member
    Join Date
    Jun 2012
    Location
    Remscheid, Germany
    Posts
    61
    Rep Power
    0

    Default Re: I don't understand what the difference is between a float and a double


  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,252
    Rep Power
    19

    Default Re: I don't understand what the difference is between a float and a double

    A double can for some values hold a more accurate representation than a float.

    To understand all about this in more detail, read What Every Computer Scientist Should Know About Floating-Point Arithmetic

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

  6. #6
    psx2514 is offline Member
    Join Date
    Oct 2012
    Posts
    50
    Rep Power
    0

    Default Re: I don't understand what the difference is between a float and a double

    Quote Originally Posted by psx2514 View Post
    So, to be more specific, could someone explain to me, for example, what the difference between double a = 2.25 and float a = 2.25f is? Also, when is it more appropriate to use a float over a double, and vice versa (I'm looking for specific examples if possible)?
    Please read that again.

  7. #7
    noctarius is offline Member
    Join Date
    Jun 2012
    Location
    Remscheid, Germany
    Posts
    61
    Rep Power
    0

    Default Re: I don't understand what the difference is between a float and a double

    Please read the answers again.

  8. #8
    killutch is offline Member
    Join Date
    Sep 2012
    Posts
    70
    Rep Power
    0

    Default Re: I don't understand what the difference is between a float and a double

    double a = 2.25 and float a = 2.25f

    in this example the value is the same. There is no difference accept the double takes up more space on the machine and each might have to be handled a little differently depending on the situation with type casting and what not.

Similar Threads

  1. What is the difference between float and double?
    By Nosrettap in forum New To Java
    Replies: 6
    Last Post: Today, 12:20 PM
  2. double and float value in java
    By arvindmer in forum New To Java
    Replies: 6
    Last Post: 05-28-2009, 04:51 PM
  3. Float vs. Double
    By javanub in forum New To Java
    Replies: 1
    Last Post: 11-23-2008, 12:11 PM
  4. Float and double to binary
    By rosh72851 in forum Advanced Java
    Replies: 3
    Last Post: 09-24-2008, 06:29 AM
  5. Put float value to double
    By chamalsl in forum New To Java
    Replies: 3
    Last Post: 09-20-2008, 04:52 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
  •