Question

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

Was it helpful?

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.

OTHER TIPS

You could try out GMP library for for arbitrary precision arithmetic. If you're using it on Windows you can neatly install it using mingw-get.

For 64bit double you could use long double, I think. I have personally never needed this.

And also there are processor extensions for longer floating point registers which I don't know much about and take a bit of effort to use for trivial tasks.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top