# Thread: Conversion from float to double

1. 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?

2. 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. 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