Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
368 views
in Technique[技术] by (71.8m points)

c++ - How do I avoid scientific notation for large numbers?

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 show me where I can see how to turn this in to a real number, by some way working with the e+301 part?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...