Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8044507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:15:07+00:00 2026-06-05T05:15:07+00:00

I have a question which arose from another question about precision of floating numbers.

  • 0

I have a question which arose from another question about precision of floating numbers.

Now, I know that floating points can not always be represented accurately and hence they are stored as the closest possible floating number that can be represented.

My question is actually about the difference in representation of float and double.

Where does this question arise from?

Suppose I do:

System.out.println(.475d+.075d);

then the output would not be 0.55 but 0.549999 (on my machine)

However, when I do :

System.out.println(.475f+.075f);

I get the correct answer, i.e. 0.55 (a little unexpected for me)

Till now I was under an impression that double has more precision(double will be more accurate upto a longer number of decimal places) that float. So, if a double cannot be represented precisely, then its equivalent float representation will also be stored inaccurately.

However the results I got are a little disturbing for me. I am confused if:

  1. I have an incorrect understanding of what precision means?
  2. float and double are represented differently, apart from the fact that double has more bits?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T05:15:08+00:00Added an answer on June 5, 2026 at 5:15 am

    Precision just means more bits. A number that cannot be represented as a float may have an exact representation as a double, but that the number of those cases is infinitely small relative to the total number of possible cases.

    For the simple cases like 0.1, that is not representable as a fixed-length floating-point number, no matter what the number of bits available. This is the same as saying that a fraction such as 1/7 cannot be represented exactly in decimal, regardless of the number of digits you are allowed to use (as long as the number of digits is finite). You can approximate it as 0.142857142857142857… repeating over and over again, but you will never be able to write it EXACTLY no matter how long you go on.

    Conversely, if a number is representable exactly as a float, it will also be representable exactly as a double. A double has a larger exponent range and more mantissa bits.

    For your example, the cause of the apparent discrepancy is that in float, the difference between 0.475 and its float representation was in the ‘right’ direction so that when truncation occurred it went how you expected it. When increasing the precision available, the representation was “closer” to 0.475 but now on the opposite side. As a gross example, let’s say that the closest possible float was 0.475006 but in a double the closest possible value was 0.474999. This would give you the results you see.

    Edit: Here’s the results of a quick experiment:

    public class Test {
    
        public static void main(String[] args)
        {
            float  f = 0.475f;
            double d = 0.475d;
    
            System.out.printf("%20.16f", f);
            System.out.printf("%20.16f", d);
        }
    }
    

    Output:

      0.4749999940395355  0.4750000000000000
    

    What this means is that the floating-point representation of the number 0.475, if you had a huge number of bits, would be just a tiny bit less than 0.475. This is see in the double representation. However, the first ‘wrong’ bit occurs so far to the right that when truncated to fit in a float, it just happens to work out to 0.475. This is purely an accident.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I Have wrote a question which got a right answer here about emysql encoding.
Earlier today I asked this question which arose from A- My poor planning and
I have a question which seems to be rather fundamental but I can't seem
I have a question which can be divided into two subquestions. I have created
I have another question which needs resolving as it is rather irritating. I have
I have a question which is described below: What problems would arise for testing
I have a question which I think involves conditional entropy in the field of
I have a question which may be somewhat silly because I'm pretty sure I
I have a question which involves calling a function with 2 parameters of a
Hey guys i have a question which i have been looking for the answer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.