Float vs. Double? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Float vs. Double?

What's the difference between a float and double interger? Are they interchangeable and if not should I always use a certain one?

31st Jul 2016, 1:41 AM
Playjoy “Kungpoww” Of Death
Playjoy “Kungpoww” Of Death - avatar
5 Answers
+ 1
do a test - define float, double and decimal. and then use them as a place to store something like 10 / 3 or pi and see how much precision you need
31st Jul 2016, 1:57 AM
Roberts L
Roberts L - avatar
0
double is more precise. floats are still precise, and in game dev terms, if you blow up the barrel and it flies for 100m - player won't care I'd landing is 2 cm off the actual point. double is more precise, but then there is decimal.
31st Jul 2016, 1:44 AM
Roberts L
Roberts L - avatar
0
So float would be 10.5 and double 10.58? Would the code be bugged if I put float for the double linterger?
31st Jul 2016, 1:46 AM
Playjoy “Kungpoww” Of Death
Playjoy “Kungpoww” Of Death - avatar
0
I'd say stick to doubles for your testing needs. it doesn't matter, until it matters. check stack overflow discussion for full theory.
31st Jul 2016, 1:54 AM
Roberts L
Roberts L - avatar
0
@Robert. Why when I tried these on code playground... float x=10/3; double y=10/3; console.writeline("float = {0}. double = {1}", x, y); the result both are 3....?
2nd Aug 2016, 9:07 AM
Jansen Tanu
Jansen Tanu - avatar