46. contoh manipulator setprecision dengan DEV C++
#include <iostream>
#include <iomanip>
using namespace std;
int main ()
{
float M,D,MD;
M = 12.34;
D = 38.56;
MD = M * D;
cout<<setiosflags(ios::fixed);
cout<<setprecision(0)<<MD<<endl;
cout<<setprecision(2)<<MD<<endl;
cout<<setprecision(4)<<MD<<endl;
cout<<setprecision(6)<<MD<<endl;
cout<<setprecision(8)<<MD<<endl;
return 0;
}
#include <iostream>
#include <iomanip>
using namespace std;
int main ()
{
float M,D,MD;
M = 12.34;
D = 38.56;
MD = M * D;
cout<<setiosflags(ios::fixed);
cout<<setprecision(0)<<MD<<endl;
cout<<setprecision(2)<<MD<<endl;
cout<<setprecision(4)<<MD<<endl;
cout<<setprecision(6)<<MD<<endl;
cout<<setprecision(8)<<MD<<endl;
return 0;
}
Komentar
Posting Komentar