In C double is a keyword for the double data type. It represents floating point numbers with better precision. Usually we associate the name with the idea that it has double the precision of the float type.
Declaring a variable is just like with any other type:
double price = 9.95;
Printing uses the format specifier %lf (%lg, %le or %la are equivalent). This is the only correct way for compilers that comply with С99 or later. Anyway, many compilers still use the ANSI way and allow printing doubles with the old %f.
printf("price: %lf", price);
Reading with scanf is done with %lf with all compilers.
printf("salary: %lf", salary);
In C double’s exact precision depends on the implementation. Most compilers today use the IEEE-754 standard. To represent the numbers they use 64 bits as follows:
It can keep up to about 16 digits before the variable is overflowed. For instance we can keep the pi number with a precision of 15 digits after the decimal point:
double pi = 3.141592653589793;
If we try to keep too much data in a variable, information will be lost. The information will be lost right to left.
bigNumber = 9876543210.123456789012345;
printf("big num: %f\n", bigNumber);
This will print 9876543210.123457 for a total of 16 digits, where the last is rounded up to 7.
Normally the range and precision of double is more than enough in practice.