0

what is difference b/w float and double

when we use float and double , give one example. bcoz I confused 10.4566 this s float or double

10th Oct 2016, 2:22 AM
Viru Ashok
Viru Ashok - avatar
3 ответов
+ 2
Float and double are the same in terms of the type of data it can store. Both of them can store numbers with decimals... The diference is the size of the space in memory they use to store the number! Double use two times the apace in bytes that float uses to store a number. The extra space is used to store more decimals of the number if needed. Of course, this give another practical diference: Double has a better precision than float and can store bigger numbers and more decimals. Also, it consume more computer resources to access Double variables than floats. So, you have to put everything in balance: do you really need the precision of a Double (like a scientific program were the maximal precission is a must)? If so, use it. If float is enought (like you want to store some currency where you will use no more than two decimal in each number), use float instead as you will use less memory and your program should run smootier...
10th Oct 2016, 2:55 AM
Nelson Urbina
Nelson Urbina - avatar
0
In both cases your code is comparing a float value to a double, as the compiler sees 3.2f as a float and 3.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 guarantee that the number you assign to the float or double is exact. It's the same for float and double - both are binary floating point types, but double has more precision than float. 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.
10th Oct 2016, 2:57 AM
Abhinav Maurya
Abhinav Maurya - avatar
0
they both are floating type data types but float is of smaller size(4-bytes) whereas,double is of bigger size(8-bytes).
10th Oct 2016, 7:06 AM
Mihir