请问c++ cout 格式 的问题在c++里 如果 想cout 一个小数,怎么规定他的小数位数呢?
eg:
num = 3.6
cout (more...)
answer:
#include <iostream.h>
#include <iomanip.h>
int main()
{
double num = 3.6;
cout << setiosflags(ios::fixed | ios::showpoint);
cout << setprecision(2);
cout << num << endl;
}
/*
refer to any iomanip formatting document for c++ io formatting
*/
#include <iomanip.h>
int main()
{
double num = 3.6;
cout << setiosflags(ios::fixed | ios::showpoint);
cout << setprecision(2);
cout << num << endl;
}
/*
refer to any iomanip formatting document for c++ io formatting
*/

You may say I'm a dreamer
but I'm not the only one...