I'm doing some math with floating point numbers and I'm getting weird results.

For instance, the result of one of my math problems has an "e" and "+" in it.

-4.49255e+013

How do I make it display a value without the weird "e" and "+"

4
Contributors
5
Replies
6
Views
8 Years
Discussion Span
Last Post by necrolin

Code?

There is no code, I'm just wondering why it does this sometimes? Is it because my float values are too big? Is it something with the math?

What does it actually mean anyway?

In my number, -4.49255e+013, does the "e+" mean the actual value is to the 13th place?

Is it because my float values are too big?

Or too small. Or too precise for fixed notation. You can print the usual way with the `fixed` manipulator.

``````#include <iostream>

using namespace std;

int main()
{
double d = -4.49255e+013;

cout << fixed << d << '\n';
}``````

But if you get values like that and do not expect them, your math might be wrong or you forgot to initialize a variable somewhere. Very large or very small values can sometimes mean an uninitialized variable.

This is required reading for anyone who has questions about floating point. You do not have to be an expert at it and understand everything, but reading it through one time will help.

Ohh I see. Usually when that happens to me, it's because my math is wrong.

There is no code, I'm just wondering why it does this sometimes? Is it because my float values are too big? Is it something with the math?

What does it actually mean anyway?

In my number, -4.49255e+013, does the "e+" mean the actual value is to the 13th place?

It's exponential notation.

2000 = 2e+3 = 2 * 10 to the power of 3

If you don't want to see exponential notation then just use fixed like Tom Gunn demonstrated. Of course it is possible that you're seeing exponential notation due to an error, but if your number gets large or small enough it simply defaults to exponential notation.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.