Search code examples
c++doublepointfloating

How can I display a big double normally instead of scientifically normalized


I'm currently trying to make a simple calculator, but I want it to use somewhat big numbers(anything above 10^10 should do). And since any decent calculator has floating point operations, I decided to use double as my type. Sadly, when I tried to write a big number(around 10^7), it went into e notation. I want to display it like a normal number.

All help is appreciated. :D


Solution

  • If you want to display all digits of your double (instead of going into scientific notation), you have to change your output stream's float formatting to std::fixed:

    Live demo on Coliru:

    double d = 1000000000000000.0; // 10^16
    std::cout << std::fixed << d;
    

    Output:

    1000000000000000.000000
    

    If you want your display to go into scientific notation at a custom exponent, you'll have to do that yourself using the existing tools.