Float is a shortened term for "floating-point." By definition, it's a fundamental data type built into the compiler that's used to define numeric values with floating decimal points. A floating-point type variable is a variable that can hold a real number, such as 4320.0, -3.33, or 0.01226. The floating part of the name floating point refers to the fact that the decimal point can “float”; that is, it can support a variable number of digits before and after the decimal point.
floating point
| Category | Type | Minimum Size | Typical Size |
|---|---|---|---|
| floating point | float | 4 bytes | 4 bytes |
| double | 8 bytes | 8 bytes | |
| long double | 8 bytes | 8, 12, or 16 bytes |
Floating-point range
| Size | Range | Precision |
|---|---|---|
| 4 bytes | ±1.18 x 10-38 to ±3.4 x 1038 | 6-9 significant digits, typically 7 |
| 8 bytes | ±2.23 x 10-308 to ±1.80 x 10308 | 15-18 significant digits, typically 16 |
| 80-bits (typically uses 12 or 16 bytes) | ±3.36 x 10-4932 to ±1.18 x 104932 | 18-21 significant digits |
| 16 bytes | ±3.36 x 10-4932 to ±1.18 x 104932 | 33-36 significant digits |
Sample
Input − a=11.23 b=6.7
Output − 75.241
Explanation − Use of Float variables. In this program, the user has two numbers (floating point numbers)means float variables. Then, the product of those two numbers is stored in a variable and displayed on the screen.
Example
#include <stdio.h>
int main() {
float a, b, c;
a=11.23; b=6.7;
c = (float)(a*b);
// Displaying result up to 3 decimal places.
printf("%3f", c);
return 0;
}Output
75.241