C++ examples for Data Type:float
Floating-Point Data Types
Data Type | Description |
---|---|
float | Single precision floating-point values |
double | Double precision floating-point values |
long double | Double-extended precision floating-point values |
Floating-Point Type Ranges
Type | Precision (Decimal Digits) | Range |
---|---|---|
float | 7 | 1.2x10^-38 to 3.4x10^38 |
double | 15 | 2.2x10^-308 to 1.8x10^308 |
long double | 19 | 3.3x10^-4932 to 1.2x10^4932 |
Here are some statements that define floating point variables:
#include <iostream> int main()/*ww w . j av a 2 s . co m*/ { float inches_to_mm {25.4f}; double pi {3.1415926}; // Ratio of circle circumference to diameter long double root2 {1.4142135623730950488L}; // Square root of 2 std::cout << "inches_to_mm:" << inches_to_mm << std::endl; std::cout << "pi: " << pi << std::endl; std::cout << "root2: " << root2 << std::endl; }