Float = Floating-point ชนิดข้อมูลพื้นฐานสำหรับตัวเลขจริง มีจุดทศนิยมที่ลอยได้ เช่น 4320.0, -3.33, 0.01226
ชนิด 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 |
ช่วงค่าและ Precision
| Size | Range | Precision |
|---|---|---|
| 4 bytes | ±1.18e-38 to ±3.4e38 | 6-9 significant digits, typically 7 |
| 8 bytes | ±2.23e-308 to ±1.80e308 | 15-18 significant digits, typically 16 |
| 80-bits (typically 12 or 16 bytes) | ±3.36e-4932 to ±1.18e4932 | 18-21 significant digits |
| 16 bytes | ±3.36e-4932 to ±1.18e4932 | 33-36 significant digits |
ตัวอย่าง
Input - a=11.23 b=6.7 Output - 75.241
คำอธิบาย - ใช้ตัวแปร Float คูณกัน แล้วแสดงผล 3 ตำแหน่งทศนิยม
ตัวอย่าง
#include <stdio.h>
int main() {
float a, b, c;
a = 11.23; b = 6.7;
c = (float)(a * b);
printf("%3f", c);
return 0;
}ผลลัพธ์
75.241