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 380 views
4 answers 446 views
4 answers 416 views
4 answers 554 views
2 answers 408 views
1 answer 134 views
...