scientific notation problem

Hello everyone! I was messing around with code a bit and found out there is something strange happening with this code:

1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>

using namespace std;

int main(){

    float PlancksConst = 6.626e-34;

    cout << PlancksConst << endl;

    return 0;
}


The output should be "6.626e-34", but it's constantly outputting "6.626e-034". Why that extra zero? Is it a problem with the compiler? I'm using Codeblocks 12.11 and GNU GCC compiler. tnx :)
http://www.cplusplus.com/reference/ios/scientific/

hehehe, theres also a zero in that example as well, #interesting!, maybe its just like that??
Hmm, that's really strange... It's ok if it's just like that not doing anything, but it bugs me so much heheh. Anyone else knows the answer?
I think it's implementation-specific. (But someone correct me if I'm wrong)

For instance, this guy has the reverse problem -- he/she's only getting 2 digits when he/she wants three!
http://stackoverflow.com/questions/1257182/only-2-digits-in-exponent-in-scientific-ofstream
I get the output of
6.626e-34

with gcc, clang, intel, sun, and ibm compilers.

also, coliru has no zero either: http://coliru.stacked-crooked.com/a/6b17248e23081b0f
Last edited on
Topic archived. No new replies allowed.