AF
HomeTagSubmit NotesAsk AnythingLoginSubscribe Us
AF
1. Feel Free to ask and submit anything on Anyforum.in 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 - anyforum.in Garima Gupta
596129560202
up-rate
4
down-rate

Answers


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 - anyforum.in Rishi Kumar
523188250042
Reply This Thread
up-rate
5
down-rate

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 - anyforum.in brianmanee
030
Reply This Thread
up-rate
3
down-rate



Post Answer
Please Login First to Post Answer: Login login with facebook - anyforum.in