I've read about the difference between double precision and single precision. However, in most cases, float and double seem to be interchangeable, i.e. using one or the other does not seem to affec...

Understanding the Context

20 Format %lf is a perfectly correct printf format for double, exactly as you used it. There's nothing wrong with your code. Format %lf in printf was not supported in old (pre-C99) versions of C language, which created superficial "inconsistency" between format specifiers for double in printf and scanf. From what I have read, a value of data type double has an approximate precision of 15 decimal places.

Key Insights

However, when I use a number whose decimal representation repeats, such as 1.0/7.0, I find tha... A Double in Java is the class version of the double basic type - you can use doubles but, if you want to do something with them that requires them to be an object (such as put them in a collection), you'll need to box them up in a Double object. Possible Duplicate: long double vs double I am unable to understand the difference between between long double and double in C and C++. Can anyone help? A double has a much higher precision due to it's difference in size.

Final Thoughts

If the numbers you are using will commonly exceed the value of a float, then use a double. Several other people have mentioned performance isssues. That would be exactly last on my list of considerations. Correctness should be your #1 consideration. Promise. But, in C++, when calling scanf and printf, the notation used to specify a double is "%lf", and that stands for long float, right?

So while a float is less precise than a double, a LONG float (presumedly called long float because it can be "longer" by having more terms) is the same accuracy and therefore essentially the same thing? Using long double I get 18/19 = 0.947368421052631578..., and 947368421052631578 is the repeating decimal. Using double I get 0.947368421052631526... However, the former is correct.