what is the difference between double and float type in java?
well if memory serves me right a double has a decimal point 1.0 and a float is a floating point number you will have to look that up because I believe you have to calculate it to get one. I do know floating point numbers are responsible for personal computers working when they were first developed.
It is the capacity of precision, so to speak. Both are "real" numbers (if we think mathematically), but floats have more limited precision. If my memory serves me right, float has 7 digits of precision, while a double has 15. But that may be wrong. Also, note that you have to explicit cast the conversion from double to float. Code like: float x = (float) 3.14; or float x = 3.14f; is neccessary, or at least it was.
float is 32 bits, double is 64 bits. So obviously, you can store the value of PI with much more precesion in a double type variable than in a float variable.
Join our real-time social learning platform and learn together with your friends!