Alright. Using what I learned from here (thanks everyone) and the other parts of the web I wrote a neat little summary of the two just in case I run into another issue like this.

In C++ there are two ways to represent/store decimal values.

Floats and Doubles

A float can store values from:

  • -340282346638528859811704183484516925440.0000000000000000 Float lowest
  • 340282346638528859811704183484516925440.0000000000000000 Float max

A double can store values from:

  • -179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.0000000000000000 Double lowest

  • 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.0000000000000000 Double max

Float's precision allows it to store a value of up to 9 digits (7 real digits, +2 from decimal to binary conversion)

Double, like the name suggests can store twice as much precision as a float. It can store up to 17 digits. (15 real digits, +2 from decimal to binary conversion)

e.g.

     float x = 1.426;
     double y = 8.739437;

Decimals & Math

Due to a float being able to carry 7 real decimals, and a double being able to carry 15 real decimals, to print them out when performing calculations a proper method must be used.

e.g

include

typedef std::numeric_limits<double> dbl; 
cout.precision(dbl::max_digits10-2); // sets the precision to the *proper* amount of digits.
cout << dbl::max_digits10 <<endl; // prints 17.
double x = 12345678.312; 
double a = 12345678.244; 
// these calculations won't perform correctly be printed correctly without setting the precision.


cout << endl << x+a <<endl;

example 2:

typedef std::numeric_limits< float> flt;
cout.precision(flt::max_digits10-2);
cout << flt::max_digits10 <<endl;
float x =  54.122111;
float a =  11.323111;

cout << endl << x+a <<endl; /* without setting precison this outputs a different value, as well as making sure we're *limited* to 7 digits. If we were to enter another digit before the decimal point, the digits on the right would be one less, as there can only be 7. Doubles work in the same way */

Roughly how accurate is this description? Can it be used as a standard when confused?

Answer from user9318444 on Stack Overflow
🌐
Microsoft Learn
learn.microsoft.com › en-us › cpp › cpp › floating-limits
Floating Limits | Microsoft Learn
October 3, 2025 - Access to this page requires authorization. You can try changing directories. ... The following table lists the limits on the values of floating-point constants.
Top answer
1 of 4
26

Alright. Using what I learned from here (thanks everyone) and the other parts of the web I wrote a neat little summary of the two just in case I run into another issue like this.

In C++ there are two ways to represent/store decimal values.

Floats and Doubles

A float can store values from:

  • -340282346638528859811704183484516925440.0000000000000000 Float lowest
  • 340282346638528859811704183484516925440.0000000000000000 Float max

A double can store values from:

  • -179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.0000000000000000 Double lowest

  • 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.0000000000000000 Double max

Float's precision allows it to store a value of up to 9 digits (7 real digits, +2 from decimal to binary conversion)

Double, like the name suggests can store twice as much precision as a float. It can store up to 17 digits. (15 real digits, +2 from decimal to binary conversion)

e.g.

     float x = 1.426;
     double y = 8.739437;

Decimals & Math

Due to a float being able to carry 7 real decimals, and a double being able to carry 15 real decimals, to print them out when performing calculations a proper method must be used.

e.g

include

typedef std::numeric_limits<double> dbl; 
cout.precision(dbl::max_digits10-2); // sets the precision to the *proper* amount of digits.
cout << dbl::max_digits10 <<endl; // prints 17.
double x = 12345678.312; 
double a = 12345678.244; 
// these calculations won't perform correctly be printed correctly without setting the precision.


cout << endl << x+a <<endl;

example 2:

typedef std::numeric_limits< float> flt;
cout.precision(flt::max_digits10-2);
cout << flt::max_digits10 <<endl;
float x =  54.122111;
float a =  11.323111;

cout << endl << x+a <<endl; /* without setting precison this outputs a different value, as well as making sure we're *limited* to 7 digits. If we were to enter another digit before the decimal point, the digits on the right would be one less, as there can only be 7. Doubles work in the same way */

Roughly how accurate is this description? Can it be used as a standard when confused?

2 of 4
15

The std::numerics_limits class in the <limits> header provides information about the characteristics of numeric types.

For a floating-point type T, here are the greatest and least values representable in the type, in various senses of “greatest” and “least.” I also include the values for the common IEEE 754 64-bit binary type, which is called double in this answer. These are in decreasing order:

  • std::numeric_limits<T>::infinity() is the largest representable value, if T supports infinity. It is, of course, infinity. Whether the type T supports infinity is indicated by std::numeric_limits<T>::has_infinity.

  • std::numeric_limits<T>::max() is the largest finite value. For double, this is 21024−2971, approximately 1.79769•10308.

  • std::numeric_limits<T>::min() is the smallest positive normal value. Floating-point formats often have an interval where the exponent cannot get any smaller, but the significand (fraction portion of the number) is allowed to get smaller until it reaches zero. This comes at the expense of precision but has some desirable mathematical-computing properties. min() is the point where this precision loss starts. For double, this is 2−1022, approximately 2.22507•10−308.

  • std::numeric_limits<T>::denorm_min() is the smallest positive value. In types which have subnormal values, it is subnormal. Otherwise, it equals std::numeric_limits<T>::min(). For double, this is 2−1074, approximately 4.94066•10−324.

  • std::numeric_limits<T>::lowest() is the least finite value. It is usually a negative number large in magnitude. For double, this is −(21024−2971), approximately −1.79769•10308.

  • If std::numeric_limits<T>::has_infinity and std::numeric_limits<T>::is_signed are true, then -std::numeric_limits<T>::infinity() is the least value. It is, of course, negative infinity.

Another characteristic you may be interested in is:

  • std::numeric_limits<T>::digits10 is the greatest number of decimal digits such that converting any decimal number with that many digits to T and then converting back to the same number of decimal digits will yield the original number. For double, this is 15.
Discussions

confused about the max limit we can store for float and double
Interestingly, a double can exactly represent any integer up to about 2^53. Here's more info on the max limits: https://en.wikipedia.org/wiki/IEEE_754 More on reddit.com
🌐 r/C_Programming
8
3
February 1, 2024
c - Limits for floating point types? - Stack Overflow
Sign up to request clarification or add additional context in comments. ... Save this answer. ... Show activity on this post. on linux, I have float.h which has FLT_MAX and DBL_MAX defined for maximum float and double values respectively. More on stackoverflow.com
🌐 stackoverflow.com
Maximum whole number a float can represe - C++ Forum
For you it would have 4 bytes, which is the same as a long int. To find out the ints max, you can initialise an int with its MAX value by: int x = INT_MAX; same with minimum. long x = LONG_MAX; cout << x; I do not know the number the float can hold though, sorry. More on cplusplus.com
🌐 cplusplus.com
April 7, 2012
Increase maximum float limit in C++
HI there, i posted a question about this a few days ago. I need to increase the maximum float value in C++, currently the limit is 18 quintillion or something along those lines, but im making an idle game so it needs to go beyond that. I looked up c++ code but i have no idea what i would use ... More on forums.unrealengine.com
🌐 forums.unrealengine.com
2
0
March 28, 2017
🌐
O'Reilly
oreilly.com › library › view › c-cookbook › 0596007612 › ch03s08.html
3.7. Getting the Minimum and Maximum Values for a Numeric Type - C++ Cookbook [Book]
November 8, 2005 - #include <iostream> #include <limits> using namespace std; template<typename T> void showMinMax() { cout << "min: " << numeric_limits<T>::min() << endl; cout << "max: " << numeric_limits<T>::max() << endl; cout << endl; } int main() { cout << "short:" << endl; showMinMax<short>(); cout << "int:" << endl; showMinMax<int>(); cout << "long:" << endl; showMinMax<long>(); cout << "float:" << endl; showMinMax<float>(); cout << "double:" << endl; showMinMax<double>(); cout << "long double:" << endl; showMinMax<long double>(); cout << "unsigned short:" << endl; showMinMax<unsigned short>(); cout << "unsigned int:" << endl; showMinMax<unsigned int>(); cout << "unsigned long:" << endl; showMinMax<unsigned long>(); }
Authors: D. Ryan StephensChristopher DigginsJonathan TurkanisJeff Cogswell
Published: 2005
Pages: 594
🌐
TutorialsPoint
tutorialspoint.com › c_standard_library › float_h.htm
C Library - <float.h>
Following is the C Library header file float.h to define the values of few macros(float) constant. #include <stdio.h> #include <float.h> int main () { printf("The maximum value of float = %.10e\n", FLT_MAX); printf("The minimum value of float = %.10e\n", FLT_MIN); printf("The number of digits in the number = %.10d\n", FLT_MANT_DIG); }
🌐
Quora
quora.com › Why-is-the-maximum-float-number-in-C-3-40282-cdot10-38
Why is the maximum float number in C++ 3.40282\cdot10^{38} ?
Answer (1 of 5): It isn’t. It IS that number (approximately, at least) if you are using a compiler for an IEEE-754[1] machine with single precision, because the 32-bit “single precision” float format has 1 bit for sign, 8 bits for exponent (biased by 127) and 23 bits for the mantissa, ...
🌐
Reddit
reddit.com › r/c_programming › confused about the max limit we can store for float and double
r/C_Programming on Reddit: confused about the max limit we can store for float and double
February 1, 2024 -

Just started learning C. so forigve me if this is a dumb question.

For int and long, the maximum number we can assign them is 2^32 and 2^64 respectively. how about for float and double? I know that double has higher precision of about 15 decimal points while float is 7.

i also know that float is 32 bit while double is 64 bit. So does that mean the highest we can store them (2^32)and (2^64) but with decimal points in between their numbers? i aslo learnt that these data type cant have unsigned value so does that value doubles?

🌐
The C Book
publications.gbdirect.co.uk › c_book › chapter9 › limits.html
The C Book — Limits
Two header files <float.h> and <limits.h> define several implementation specific limits. Table 9.1 gives the names declared, the allowable values, and a comment on what they mean. For example, the description of SHRT_MIN shows that in a given implementation the value must be less than or equal to −32767: this means that for maximum ...
🌐
GNU
gnu.org › s › libc › manual › html_node › Floating-Point-Parameters.html
The GNU C Library - GNU Project - Free Software Foundation (FSF)
This glibc manual version 2.44 (latest) is available in the following formats: · The manual is available for the following releases of glibc:
Find elsewhere
🌐
Arm
support.arm.com › documentation › dui0041 › c › ARM-Compiler-Reference › Limits-for-floating-point-numbers
ARM Software Development Toolkit Reference Guide
December 16, 2024 - The following tables give the characteristics, ranges, and limits for floating-point numbers as implemented in ARM C and C++. Note also:
🌐
Microsoft Learn
learn.microsoft.com › en-us › cpp › c-language › type-float
Type float | Microsoft Learn
The floating-point package never uses a denormalized form unless the exponent becomes less than the minimum that can be represented in a normalized form. The following table shows the minimum and maximum values you can store in variables of each floating-point type.
🌐
GeeksforGeeks
geeksforgeeks.org › c++ › stdnumeric_limitsmax-and-stdnumeric_limitsmin-in-c
std::numeric_limits::max() and std::numeric_limits::min() in C++ - GeeksforGeeks
July 23, 2025 - bool: 0 char: -128 unsigned char: 0 short: -32768 int: -2147483648 unsigned int: 0 long long: -9223372036854775808 float: 1.17549e-38 double: 2.22507e-308 size_t: 0
🌐
Wikipedia
en.wikipedia.org › wiki › Single-precision_floating-point_format
Single-precision floating-point format - Wikipedia
July 31, 2026 - Single-precision floating-point ... numeric values by using a floating radix point. A floating-point variable can represent a wider range of numbers than a fixed-point variable of the same bit width at the cost of precision. A signed 32-bit integer variable has a maximum value of 231 ...
🌐
Cplusplus
cplusplus.com › forum › general › 67783
Maximum whole number a float can represe - C++ Forum
April 7, 2012 - Depends on the number of bits used for the exponent. http://en.wikipedia.org/wiki/Single-precision_floating-point_format ... This is what the numeric_limits class is designed for. See http://cplusplus.com/reference/std/limits/numeric_limits/ and http://cplusplus.com/reference/clibrary/cfloat/ I get really weird values for max() -- see digits10 and the like to calculate something more reasonable.
🌐
cppreference.com
en.cppreference.com › c › types › limits
Numeric limits - cppreference.com
Similarly USHRT_MAX may not be of an unsigned type: its type may be int. A freestanding implementation may lack sig_atomic_t and/or wint_t typedef names, in which case the SIG_ATOMIC_* and/or WINT_* macros are correspondingly absent.
🌐
Cplusplus
cplusplus.com › reference › limits › numeric_limits
std::numeric_limits
Provides information about the properties of arithmetic types (either integral or floating-point) in the specific platform for which the library compiles. This class template is specialized for every fundamental arithmetic type, with its members describing the properties of type T.
🌐
Unreal Engine
forums.unrealengine.com › development › programming & scripting › c++
Increase maximum float limit in C++ - C++ - Epic Developer Community Forums
March 28, 2017 - HI there, i posted a question about this a few days ago. I need to increase the maximum float value in C++, currently the limit is 18 quintillion or something along those lines, but im making an idle game so it needs to go beyond that.
🌐
Cplusplus
cplusplus.com › forum › beginner › 83526
float and double - C++ Forum
October 31, 2012 - I understood that integer can have numbers from 0 to 65536. but didn't understand the limitations of the float and double. ... Minimum value for a float is 1.175494351 E – 38 (if you're not familiar with "E" it means "*10^"). Max float is 3.402823466 E + 38.
🌐
LabEx
labex.io › tutorials › java-how-to-use-the-float-max-method-to-find-the-maximum-of-two-float-values-414166
How to use the Float max method to find the maximum of two float values | LabEx
The syntax for using the Float.max() method is as follows: ... Here, a and b are the two float values to be compared, and the method returns the greater of the two values.