1/6
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai | Chat |
|---|
No analytics yet
Send a link to your students to track their progress
Floating -point numbers
< Represent numbers with a decimal place like 3.1415927, 0.0000625, and 10.2 >
What are the Floating-point numbers?
Floating-point numbers in C++ represent signed real numbers with fractional parts, stored similarly to scientific notation. They follow the IEEE 754 standard, organizing data into a sign bit, exponent, and mantissa. Three primary built-in types handle non-integer values.
Float
Single precision. Uses 4 bytes of memory. Offers ~7 significant digits of precision.
Double
Double precision. Uses 8 bytes of memory. Offers ~15 significant digits of precision.
Long Double
Extended precision. Uses 8, 12, or 16 bytes depending on the system.
2 ways to be expressed
- Fixed point (decimal) notation: 31.4159, 0.0000625
- E notation: 3.14159E1, 6.25e-5
Double by default
They are double by default. Can be forced to be float = 3.14159F or long double = 0.0000625L. If a floating-point value is assigned to an integer variable, the fractional part will be truncated (i.e., 'chopped off' and discarded). Example:
int rainfall = 3.88;
cout << rainfall; // Displays 3 only