How to display a float with two decimal places in C++

1 Answer

0 votes
#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
	float pi = 3.14159265359;
	
	cout << fixed << setprecision(2) << pi << endl;

	return 0;
}


/*
run:

3.14

*/

 



answered Dec 2, 2016 by avibootz

Related questions

2 answers 386 views
4 answers 453 views
4 answers 421 views
4 answers 568 views
2 answers 413 views
1 answer 139 views
...