Disabling scientific notation in streams

I looked at the format flags for streams but I can't get them to do what I want. The default behavior works fine except when the numbers are very small. Here is what I tried and what I would like to do:

cout<<setprecision(2)<<1<<" "<<2.3<<" "<<0.000004;
output: 1 2.3 4e-006

cout<<fixed<<setprecision(2)<<1<<" "<<2.3<<" "<<0.000004;
output 1 2.30 0.00

What I would like to do:
cout<<???<<setprecision(2)<<1<<" "<<2.3<<" "<<0.000004;
output: 1 2.3 0 or 0.00
It isn't possible to make very small numbers output as decimals and not scientific notation. You can try this though, it may work for very small numbers:
1
2
3
4
5
6
7
cout << int(MyDouble) << '.';
MyDouble -= int(MyDouble);
while(MyDouble > 0)
{
    MyDouble *= 10;
    cout << int(MyDouble);
}
Then again, it may never end, so you would want to limit it.
Last edited on
Topic archived. No new replies allowed.