Display a number decimal format instead as an exponential in cout

前端 未结 2 1018
我在风中等你
我在风中等你 2021-01-27 12:33

I calculated a total of floats and I got a number like 509990e-405. I\'m assuming this is the short version; how can I cout this as a full number?

相关标签:
2条回答
  • 2021-01-27 13:22

    You can write your own BigNumber class that stores the results as strings. You would have to implement all of your numeric operations and I'm guessing performance will be an issue. But it can be done, no problem -- assuming that is what you want.

    0 讨论(0)
  • 2021-01-27 13:24

    You can force the output to be not in scientific notation, and to have the sufficient precision to show your small number.

    #include <iomanip>
    
    // ...
    
    long double d = 509990e-405L;
    std::cout << std::fixed << std::setprecision(410) << d << std::endl;
    

    Output:

    0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000050999000000

    If you really want this is another question.

    0 讨论(0)
提交回复
热议问题