Floating-point Numbers

Numbers with a decimal fraction are called floating-point numbers. They are used to model real numbers from mathematics. C++ has three different floating-point types: float, double, and long double.

Floating-point literals in C++ are written in two ways:

You can change the storage of your literals by appending an F for type float and an L for a type long double.

Here are some examples of floating-point literals:

auto a = 3.14159;       // fixed notation, type double
auto b = 2.997E8;       // scientific notation, type double
auto c = 299'792'458.L; // fixed notation, type long double
auto d = 3.5F;          // fixed notation, type float

Generally, use double, not float or long double.