when I...
double a = 0.00000001;
cout<< a <<endl;
The computer outputs 1e-07. I want to force the computer to write it as 0.00000001
thanks! ;)
I also need to be able to right justify items I am printing, or add 0's to the beginning of integers so that they ALL are exactly 8 digits long. (my ints do not exceed 99999999)
setprecision must take away digits, but it will not add 0's when the integer is not long enough!
Thank you for your help so far. That was very useful and allowed me to fix part of my code :)
Well if you are only using positive numbers you can use setfill() and right() to get padded zeros. if you are going to have negative numbers then I think some string manipulation will be in order.
setfill -> http://www.cplusplus.com/reference/iostream/manipulators/setfill/
right -> http://www.cplusplus.com/reference/iostream/manipulators/right/
There is one last question that I have. If I use "fixed" to fix my number formats, but later in my program I no longer want the fixed, how do I return to the default?
see: http://www.cplusplus.com/reference/iostream/manipulators/fixed/
help please
If you scroll to the bottom of that website you linked you will see unsetf().
Here is an example
#include <iostream>
using namespace std;
int main()
{
cout.setf(ios_base::fixed);
cout << 100.1 << endl; //with fixed
cout.unsetf(ios_base::fixed);
cout << 100.2 << endl; //without fixed
return 0;
}
thank you so much man. i will be using this tomorrow ;)
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.