
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
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 −
24.25 12.00
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 −
Example
#include<iostream> 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; }
Output
This will give the output −
3.141
- Related Articles
- What are floating point literals in C#?
- C++ Floating Point Manipulation
- Explain what floating point numbers are and what types of floating points are available in Swift
- What are constants in C++?
- What are C++ Integer Constants?
- What are C++ Character Constants?
- Floating point comparison in C++
- What are Enumerated Constants in C++?
- What is the precision of floating point in C++?
- What are different types of constants in C++?
- What are Backslash character constants in C language?
- Why are floating-point calculations inaccurate in Python?
- Integer literals vs Floating point literals in C#
- C Program to Multiply two Floating Point Numbers?
- Signed floating point numbers

Advertisements