By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,227 Members | 1,310 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,227 IT Pros & Developers. It's quick & easy.

Exponential

P: n/a
In this code the exponential part using scientific notation becomes
e+002 is ther a way of changging the number of values after e so they
can appear like e+02, only 2 values instead 3??

I have been thinking a lot about this!!!
any comments
// modify floatfield using manipulators
#include <iostream>
using namespace std;

int main () {
float f;
f=365.25;
cout << fixed << f << endl;
cout << scientific << f << endl;
return 0;
}

The execution of this example shall display:
365.250000
3.652500e+002

Jul 23 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
<di**********@gmail.com> wrote...
In this code the exponential part using scientific notation becomes
e+002 is ther a way of changging the number of values after e so they
can appear like e+02, only 2 values instead 3??
There is no way using C++ manipulators only, if that's what you're
asking.

The reason is in the C library. C++ specifies that 'scientific' shall
cause the output to be the same as %e (or %E if 'uppercase' is set) in
fprintf. In C++ %e causes output of as many digits in the exponent as
necessary to represent the exponent. On your system 'double' (and that
is what your 'float' is converted to) has probably three digits of the
exponent, and that's why it prints e+002.

The only way to achieve 2 digits in your output is to perform your own
conversion to, say, a string, and then output that string.
I have been thinking a lot about this!!!
any comments
// modify floatfield using manipulators
#include <iostream>
using namespace std;

int main () {
float f;
f=365.25;
cout << fixed << f << endl;
cout << scientific << f << endl;
return 0;
}

The execution of this example shall display:
365.250000
3.652500e+002

Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.