Values must contain a floating-point. You can omit digits before the decimal point or digits after the decimal point, but not both. Floats cannot be signed or unsigned. Meaning they are essentially signed by default.
[float|double] = <value>
float myFloat = 125.8f; float myFloat2 = 3.0f; float myFloat3 = -.001f; printf("Value of myFloat is: %g \n", myFloat); printf("Value of myFloat2 is: %g \n", myFloat2); printf("Value of myFloat3 is: %g \n", myFloat3);
The reason you need to add the character
F) to the declaration is to explicitly tell the compiler to treat the variable as a float. As by default floating-point constants are taken as a
double by the C compiler.
double myDouble = 125.8; double myDouble2 = 3.; double myDouble3 = -.001; printf("Value of myDouble is: %g \n", myDouble); printf("Value of myDouble2 is: %g \n", myDouble2); printf("Value of myDouble3 is: %g \n", myDouble3);
double cannot have range specifiers like
float is generally 4 bytes in size (32 bits wide).
double is generally 8 bytes in size (64 bits wide).