C language decimal types include: float: single-precision floating point number, 7-digit precision, occupying 32-bit memory. double: double-precision floating-point number, 15-bit precision, occupying 64-bit memory. Select the type according to the precision requirements. Use float for low precision and double for high precision. Floating point numbers can be converted implicitly but with loss of precision, and very large or small numbers can be expressed in scientific notation.
Decimal types in C language
C language provides two decimal types, respectively:
Select a type
Which decimal type you choose depends on the required precision and memory consumption. For calculations requiring lower precision, the float type is sufficient. But for demanding calculations that require higher precision, it is recommended to use the double type.
Precision comparison
The following table compares the precision of the following values when they are of different types:
Value | float | double |
---|---|---|
0.123000 | 0.12300000000000000 | |
12345.679 | ##12345.67890625 |
The float type occupies 32-bit memory space, while the double type occupies 64-bit memory space. Therefore, when you need to process a large amount of decimal data and have limited memory, choosing the float type can save memory.
Note
Decimal types can be implicitly converted. For example, a float variable can be assigned to a double variable, but the opposite conversion will lose precision.
The above is the detailed content of What are the decimal types in C language?. For more information, please follow other related articles on the PHP Chinese website!