Reputation: 24500
I only see how to do it using printf:
printf(" salary = %.2f" , salary) ;
But how to specify it in standard cout function? Do any coders know?
Upvotes: 0
Views: 184
Reputation: 24500
cout<< fixed <<setprecision(2)<< result<<endl ;
This is the right answer - fixed must be there!
Upvotes: 0
Reputation: 448
Use cout.precision()
eg.
int main ()
{
cout.precision(5);
double i = 1.23556456123;
cout << i;
}
Upvotes: 1
Reputation: 17936
std::cout << std::setprecision(2) << salary;
More here: http://www.cplusplus.com/reference/iomanip/setprecision/
You might want to check out the rest of the iomanip stuff too: http://www.cplusplus.com/reference/iomanip/
Upvotes: 2