iomanip - STL C++

setprecision()

Declaration

(unspecified) setprecision(int iDigits);

Description

This is the setprecision() function for output stream manipulation. The argument iDigits sets the number of digits of precision used for numerical output.

Header Include

#include <iomanip>

Example

#include <iostream>
#include <iomanip>

int main() {
	using namespace std;

	double dPi = 3.14159;
	// Output the value with default settings
	cout << "Default: " << dPi << endl;

	// Output the value with the precision set
	cout << setprecision(3);
	cout << "With 3 decimal places: " << dPi << endl;

	// Keep the window open
	cin.get();
	return 0;
}

Output

setprecision() Output
 

© 2007–2024 XoaX.net LLC. All rights reserved.