What are C++ Floating-Point Constants?

Floating-point constants specify values that must have a fractional part.

Floating-point constants have a "mantissa," which specifies the value of the number, an "exponent," which specifies the magnitude of the number, and an optional suffix that specifies the constant's type(double or float).

The mantissa is specified as a sequence of digits followed by a period, followed by an optional sequence of digits representing the fractional part of the number. For example −


These values can also contain exponents. For example,

24.25e3 which is equivalent to 24250

In C++ you can use the following code to create a floating point constant −


Live Demo

using namespace std;
int main() {
   const float PI = 3.141;  // 3.141 is floating point constant while PI is a constant float.
   cout << PI;
   return 0;


This will give the output −

Lakshmi Srinivas
Lakshmi Srinivas

Programmer / Analyst / Technician