What is the difference in using 'float' and 'double' data type in C language? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What is the difference in using 'float' and 'double' data type in C language?

21st Dec 2018, 2:52 PM
Dipra Irham
Dipra Irham - avatar
4 Answers
+ 3
float is a 32bit number, double is a 64bit number. Therefore double can store bigger numbers and they are more precise. double is also the standard floating point type in modern compilers.
21st Dec 2018, 6:43 PM
Chris
Chris - avatar
+ 3
My C++ professor recommended to never use Doubles because they take up alot more memory than Floats. The more complex your code the more you have to worry about memory requirements to keep code running fast.
21st Dec 2018, 9:48 PM
Victor Oliveros
Victor Oliveros - avatar
+ 3
Memory usually isn't an issue nowadays, but it depends on the project (application size, intended hardware,...) In most cases, you're safe when using doubles. Nobody ever recommended me using floats instead of doubles, except in machine learning, but there you're handling a massive amount of data at the same time. If you want to use floats anyway, just remember to use float literals (e.g. 1.0f instead of 1.0) when using constants in calculations, because otherwise the compiler will use double
21st Dec 2018, 9:52 PM
Chris
Chris - avatar
+ 3
Abu Sufian They are able to store larger numbers because the have more bits.
28th Dec 2018, 4:15 PM
Chris
Chris - avatar