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 1071617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:44:20+00:00 2026-05-16T20:44:20+00:00

This is what happens on my computer: (double)(float)0.6 = 0.60000002384185791 (double)0.6f = 0.60000002384185791 (double)(6/10f)

  • 0

This is what happens on my computer:

(double)(float)0.6
= 0.60000002384185791

(double)0.6f
= 0.60000002384185791

(double)(6/10f)
= 0.6

(double)(float)(6/10f)
= 0.6

6/10f is also a float,how come it can be precisely 0.6?
In my mind (double)(6/10f) should also be 0.60000002384185791.
Can someone help explain this? thanks!

  • 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-05-16T20:44:20+00:00Added an answer on May 16, 2026 at 8:44 pm

    First, its important to bear in mind that 0.6 cannot be accurately represented as a float however it can be accurately represented as a double (the inaccuracies of floating point arithmetic are well documented, if its not clear why 0.6 cannot be accurately represented as a float, try this link)

    The reason why you are seeing the above behaviour is down to the compiler – if you take a look at the compiled assembly in reflector then whats going on here is a little clearer:

    (UPDATE I’ve changed the code so that it doesn’t use Console.WriteLine, as I realised that the compiler was choosing an overload for you, which confused the situation)

    // As written in source
    var j = (double)(float)0.6;
    var k = (double)0.6f;
    var l = (double)(6/10f);
    var m = (double)(float)(6/10f);
    
    // Code as seen by Reflector
    double j = 0.60000002384185791;
    double k = 0.60000002384185791;
    double l = 0.6;
    double m = 0.6;
    

    Why the compiler chooses to compile in this particular way is beyond me (fyi, this is all with optimisations turned off)

    Some interesting other cases:

    // Code
    var a = 0.6;
    var b = (double)0.6;
    var c = 0.6f;
    var d = (float)0.6;
    
    var e = 6 / 10;
    var f = 6 / (10f);
    var g = (float)(6 / 10);
    var h = 6 / 10f;
    var i = (double)6 / 10;
    // Prints out 0.60000002384185791
    
    double n = (float)0.6;
    double o = f;
    
    // As seen by Reflector
    double a = 0.6;
    double b = 0.6;
    float c = 0.6f;
    float d = 0.6f;
    
    int e = 0;
    float f = 0.6f;
    float g = 0f;
    float h = 0.6f;
    double i = 0.6;
    
    double n = 0.60000002384185791;
    double o = f;
    

    The compiler only seems to do the above trick in a couple of special cases, why it does this only when casting to a double is completely beyond me!

    The rest of the time it seems to do some trickery to make floating point arithmetic seem to work where in fact it normally wouldn’t.

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

Sidebar

Related Questions

This happens almost every time I init a new repo. Start a new project.
This happens after I hit Build and Go to run my app on my
This happens in IDLE and Windows 7 RC1 (if that helps). Here is the
I am authenticating users in ldap, but this happens only once, when user is
I need to catch segmentation fault in third party library cleanup operations. This happens
MacPorts installed libiconv @1.14_0+universal as a dependency on my system. This happens to be
Sometimes users mistakenly redirected to ?Process=ViewImages&PAGEID=. When this happens, they get the following error.
This only happens in some IE's. Here: http://animactions.ca/Animactions/volet_entreprise.php You may notice that when you
This only happens in IE. I'm using swfobject and loading the flash vars as
This often happens to me: I'm working on a couple related changes at the

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.