I want to print a double value to std::cout portably (GCC, clang, MSVC++) such that the output is the same on all platforms.
I have a problem with the formatting of the exponent. The following program
#include <iostream>
int main()
{
std::cout << 0.1e-7 << std::endl;
return 0;
}
Has this output with GCC:
1e-08
and the following output with MSVC
1e-008
How can I make both outputs the same?
I'm sorry if this is a dumb question but I have not found an answer so far. All formatting seems to evolve around the formatting of everything before the mantissa...
EDIT: The output of GCC is 1e-08 not 1e-8 (as originally stated) so it is conforming. Sorry for the confusion.
EDIT2: Actually renamed "mantissa" to "exponent" following Dietmar's remark. There also is a section on Wikipedia on mantissa vs. significant.