Double? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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?

8th Jan 2018, 6:08 PM
Isabella Bght
Isabella Bght - avatar
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.
8th Jan 2018, 6:49 PM
John Wells
John Wells - avatar
+ 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
8th Jan 2018, 7:33 PM
Isabella Bght
Isabella Bght - avatar
+ 1
float can only keep 7 columns of digits, while double can do 15. floats range is 10^38, while double is 10^308.
8th Jan 2018, 7:57 PM
John Wells
John Wells - avatar
- 2
for java: your standard type is double and even if you specifically create a float, java internally calculates with doubles
8th Jan 2018, 9:24 PM
Jeremy
Jeremy - avatar