Using format specifiers for floats and doubles
Floating-point numbers are floats, doubles, and long doubles that can be expressed in a number of ways mathematically. They can be expressed naturally where there is a whole number part and a fractional part. They can be expressed in scientific notation where there is a coefficient raised to a power of 10
, and it takes the 1.234567 x 10^123
form. The decimal point floats in such a way that the coefficient has a whole number part that is between 1
and 10
and the exponent is adjusted accordingly. C provides both of these formats.
The next example program is double.c
, and it begins as follows:
#include <stdio.h>
int main( void ) {
double aDouble = 987654321.987654321;
// the other code snippets go here.
}
In this program, only one value is defined. Whenever the value is to be converted into float
, it...