HomeTagSubmit NotesAsk AnythingLoginSubscribe Us
1. Feel Free to ask and submit anything on and get satisfactory answer
2. Registration is not compulsory, you can directly login via google or facebook
3. Our Experts are looking for yours ?.

programming-basics: what is difference between float and double?

which one is flexible and why float have more roundtrips. and which one should we use?

programming x 169
basics x 171
Posted On : 2014-07-05 14:10:47.0
profile Garima Gupta - Garima Gupta


In both cases your code is going to compare a float value to a double, as the compiler sees 4.2f as a float and 4.2 (without the f) as a double.

* The float data type is a single-precision 32-bit
* The double data type is a double-precision 64-bit

You shouldn´t ever compare floats or doubles for equality, you can´t really assure that the number you assign to the float or double is exact.

By default java assumes a manually specified number to be a double, as a double would more precisely cover more numbers that you could type in. You have to cast between doubles and float explicitly.

* A float is a 32 bit IEEE 754 floating point.
* A double is a 64 bit IEEE 754 floating point.

so it is just a matter of precision because neither of the fraction portions .8 and .65 have a terminating binary representation, so there is some rounding error. the double has more precision so it has slightly less rounding error.

Posted On : 2014-07-05 14:35:04
Satisfied : 1 Yes  0 No
profile Rishi Kumar - Rishi Kumar
Reply This Thread

The Decimal, Double, and Float variable types are different in the way that they store the values. Precision is the main difference where float is a single precision (32 bit) floating point data type, double is a double precision (64 bit) floating point data type and decimal is a 128-bit floating point data type.

Posted On : 2014-09-23 13:17:44
Satisfied : 1 Yes  0 No
profile brianmanee - brianmanee
Reply This Thread

Post Answer
Please Login First to Post Answer: Login login with facebook -