Thread: Conversion from float to double

  1. #16
    Registered User Ward's Avatar
    Join Date
    Sep 2001
    Location
    Belgium
    Posts
    39
    I understand your explaination, but this is not getting met further.
    I've posted earlier what my real goal is. Where I need this conversion for.

    I find it strange that when we cast a float fValue(250.84f) to a double the result is about 250.8399996. In this case the precision of the float in only 3 digits and not 7 as said by JasonD.

    Can you explain this problem?
    Greetings.

  2. #17
    Registered User
    Join Date
    Sep 2003
    Posts
    135
    The float value is not 250.84. It's the compilers representation of 250.84 for type float, which is close but not exactly 250.84.

    No further explanation necessary - floating point representation is not exact, it's approximate.

    Something to note here, though, is that if you initialise a float directly with 250.84 and then initialise a double directly with 250.84 they will not necessarily contain the same value, as the double has greater precision. (In fact, you may find that 250.84 can be exactly represented using double).

    If, on the other hand, you initialise a float directly with 250.84, then assign that value to a double, they will both hold the same value (as the float).

  3. #18
    jasondoucette.com JasonD's Avatar
    Join Date
    Mar 2003
    Posts
    278
    Originally posted by Ward
    According to me JasonD is disgussing the comparisation of the representation of real numbers. I don't want to take this 'thread' to that problem, sorry (thanks for the response anyway).
    I'm very certain that my float-values have a precision of 4 digits at most.
    Ward, I am not disguising anything. I gave an accurate analogy of how floating point numbers are stored, so that you can understand. I believe the cause of your problem is your misunderstanding of how they are stored. Believe me: floats can store 7-8 decimal digits, and doubles can store 15-16 decimal digits. How many of these digits are significant is another problem, to which I gave a suitable answer. If you do not know what significant digits are, then this is a serious drawback for your attempt to make a program that deals specifically with them. Please let me know where you stand from here, so we can continue to help you in the most appropriate way.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Conversion From C++ To C
    By dicon in forum C++ Programming
    Replies: 2
    Last Post: 06-10-2007, 02:54 PM
  2. need some help with last part of arrays
    By Lince in forum C Programming
    Replies: 3
    Last Post: 11-18-2006, 09:13 AM
  3. Replies: 14
    Last Post: 06-28-2006, 01:58 AM
  4. Unknown Math Issues.
    By Sir Andus in forum C++ Programming
    Replies: 1
    Last Post: 03-06-2006, 06:54 PM
  5. Im stuck....
    By dAzed in forum C++ Programming
    Replies: 8
    Last Post: 10-11-2004, 04:50 PM