+ 1

What is the difference between float and double?

3rd Dec 2016, 11:14 PM
Hamza Muric
Hamza Muric - avatar
4 Respostas
+ 2
Which type to use depends on your needs. If you have a large volume of data use float to save memory. Otherwise, doubles are better because of their higher precision. On Intel desktops and laptops floats will be converted to doubles in the processor anyway. In short, use double unless you are running low on memory, then use float.
4th Dec 2016, 11:21 PM
Gordon Garmaise
Gordon Garmaise - avatar
+ 1
the alloted memory float i believe has 4 bytes and double has 2x4 = 8bytes
3rd Dec 2016, 11:15 PM
Alex Lewis
Alex Lewis - avatar
+ 1
Generally speaking, a float is 32 bits (4 bytes) and a double is 64 bits (8 bytes). Thus a double has greater range and precision than a float. For compiled languages (C, C++, C# and objective C) it may vary depending on the target architecture. In some cases they may be the same, but the standard requires that a double will be at least as large as a float in range and precision. In Java both are determined by the JVM.
3rd Dec 2016, 11:26 PM
Gordon Garmaise
Gordon Garmaise - avatar
+ 1
But why are all those bits important. If I want to define a decimal value, what of these two should I use?
3rd Dec 2016, 11:39 PM
Hamza Muric
Hamza Muric - avatar