VOOZH about

URL: https://www.geeksforgeeks.org/cpp/iomanip-setprecision-function-in-c-with-examples/

⇱ iomanip setprecision() function in C++ with Examples - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

iomanip setprecision() function in C++ with Examples

Last Updated : 12 Jul, 2025

The setprecision() method of iomanip library in C++ is used to set the ios library floating point precision based on the precision specified as the parameter to this method.

Syntax:

setprecision(int n)

Parameters: This method accepts n as a parameter which is the integer argument corresponding to which the floating-point precision is to be set.

Return Value: This method does not return anything. It only acts as stream manipulators.

Example 1:


Output: 
Before setting the precision: 
3.14286
Setting the precision using setprecision to 5: 
3.1429
Setting the precision using setprecision to 9: 
3.14285714

Example 2:


Output: 
Before setting the precision: 
3.140000
Setting the precision using setprecision to 5: 
3.14000
Setting the precision using setprecision to 9: 
3.140000000

Reference: https://cplusplus.com/reference/iomanip/setprecision/
 

Comment