Variable will not store more than 6 digits in console app?

Hi friends, I am studying C++ and have been practicing with a console app.
At one point when doing some calculations with the app, I realized that my variable will not store a number more than 6 digits.

I am using a long double variable.
According to my literature, I thought it should work no problem, so I do not know what I am doing wrong, or what is limiting it from displaying correctly.

It will store 999,999 and print it out correctly no problem, but if it goes to 7 digits, it will not print out the accurate number but instead it is like it scrambles and adds letters and symbols into what it prints out.
Instead of displaying 1,000,000, it instead displays "1e+06".

I checked the Microsoft Windows Calculator app to see how many numbers it can store and display, and it holds up to 16 digits, but when it hits 17 digits, it appears just like my scrambled numbers.

Anyway, thank you for taking the time to read my question, and I appreciate any guidance! :]


Last edited on
closed account (48T7M4Gy)
http://www.cplusplus.com/forum/beginner/34088/
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <iomanip>

int main()
{
    const double a = 7.0 ;
    const double b = 12345657.897 ;

    std::cout << a << ' ' << b << '\n'  // default: 7 1.23457e+07
              << std::scientific << a << ' ' << b << '\n' // scientific: 7.000000e+00 1.234566e+07
              << std::fixed << a << ' ' << b << '\n' // fixed, default precision: 7.000000 12345657.897000
              << std::setprecision(2) << a << ' ' << b << '\n' ; // fixed, 2 digits after decimal point: 7.00 12345657.90
}

http://coliru.stacked-crooked.com/a/12fdb4be6be20405

See: https://stdcxx.apache.org/doc/stdlibug/28-3.html#2832
Topic archived. No new replies allowed.