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 "+"

Recommended Answers

All 5 Replies

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.