How do I avoid scientific notation for large numbers?

后端 未结 8 1168
Happy的楠姐
Happy的楠姐 2020-12-15 05:04

I am doing 2^1000 and I am getting this:

1.07151e+301

Is there any way to actually turn this into a proper number without the e+301, or at least can anyone s

相关标签:
8条回答
  • 2020-12-15 05:52

    So, I'm thinking that what you really want is just the ability to print it without scientific notation. If you're using printf, what you want is:

    printf( "%f1000.0", value );
    // note that 1000 is way larger than need be,
    // I'm just too lazy to count the digits
    

    With cout, try something like:

    cout.setf(ios::fixed);
    cout << setprecision(0) << value;
    

    If you want to print it as a power of two (2^1000 vs 10715...), you're on your own.

    0 讨论(0)
  • 2020-12-15 05:54

    You are getting as precise a number as the variable type can support. That number is on the order of 1 followed by 301 zeroes. To get a precise number you'll have to work with a library that supports large numbers, or work with a language that is made for that kind of math (maple, matlab, etc)

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