Skip to content
Related Articles

Related Articles

std::numeric_limits::digits in C++ with Example

View Discussion
Improve Article
Save Article
Like Article
  • Last Updated : 12 Jun, 2020

The std::numeric_limits::digits function in C++ STL is present in the <limits> header file. The std::numeric_limits::digits function is used to find the number of radix digits that the data type can represent without loss of precision.

Header File:



static const int digits;
static constexpr int digits;



Parameter: The function std::numeric_limits<T>::digits does not accept any parameter.

Return Value: The function std::numeric_limits<T>::digits returns the number of radix digits that the type can represent without loss of precision.

Below is the program to demonstrate std::numeric_limits<T>::digits in C++:


// C++ program to illustrate
// std::numeric_limits<T>::digits
#include <bits/stdc++.h>
#include <limits>
using namespace std;
// Driver Code
int main()
    // Print the numeric digit for
    // the various data type
    cout << "For int: "
         << numeric_limits<int>::digits
         << endl;
    cout << "For float: "
         << numeric_limits<float>::digits
         << endl;
    cout << "For double: "
         << numeric_limits<double>::digits
         << endl;
    cout << "For long double: "
         << numeric_limits<long double>::digits
         << endl;
    return 0;


For int: 31
For float: 24
For double: 53
For long double: 64


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!