0
Double?
Why did the example say double y = 20 ? Shouldnât it be a float instead, because 20 is not a very precise number. I thought float was ~32 bits (several characters) and double was ~64 bits(15+ characters) or are these terms interchangeable and are mostly used for the readersâ purposes?
4 Answers
+ 2
A character is 8 bits so float is 4 and double is 8. I and most people use double because it can handle bigger numbers and more digits of the numbers. Floats a really a hangover from the days where memory was tight and every character mattered. Since people tend to use the same types in every code they write, it makes sense for examples to point you towards the bigger/better choice.
+ 1
Thank you very much. I thought maybe less bits was faster but I guess the difference is too minimal to take that into account. I understand now, so floats would work in that example but arenât necessary and are more tedious(can only do few digits). *Clarify if I am wrong
+ 1
float can only keep 7 columns of digits, while double can do 15. floats range is 10^38, while double is 10^308.
- 2
for java: your standard type is double and even if you specifically create a float, java internally calculates with doubles