Apart from the memory size of both data types, I want to know any other differences and also want to know when we use float and when we use double?
1 Answers
You can look up the concrete difference between float
and double
variables easily by searching for those terms; this group is not for answering simple definition queries, and anyway the details vary depending on your programming language and implementation.
But you can reason from fundamental principles about what the answer must be like. Increased memory size for a data type is a cost. A cost must be offset by some benefit, otherwise people wouldn't bother having the costly type in the first place. The principal assets that computing systems deal in are time and space. Therefore, increased space requirements probably allow us to perform some computation in less time.
Why would this be? Doesn't double
simply support the same computation with higher precision? It is only the same computation as long as you don't actually are about that higher precision. If you do care about a certain level of precision, then double
allows you to do things in one step that you would otherwise have to emulate with multiple float
operations.
And there you have your answer: double
allows you to perform calculations in a particular range or at a particular precision that is greater than the range, or the precision, you could achieve with float
values. This means that it very much depends on the details of your task description whether or not it is worthwhile to use the smaller or the larger numeric type. (And that is exactly the answer you'd get if you simply asked that question e.g. in a C programming forum.)

- 107,706
- 45
- 295
- 310
-
`double` is usually recommended for individual variables (as opposed to large arrays) because your CPU can do double math about as quickly as it can do float math, so there's not much downside. – user253751 Feb 22 '21 at 15:17