How to use setprecision in C++

2 Answers

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

int main() {
    double d = 23.81489;

    std::cout << std::setprecision(5) << d;
    
    return 0;
}
 
 
 
 
/*
run:
 
23.815
 
*/

 



answered May 17, 2021 by avibootz
0 votes
#include <iostream>
#include <iomanip>

int main() {
    double d = 23.81489;

    std::cout << std::fixed << std::setprecision(4) << d;
    
    return 0;
}
 
 
 
 
/*
run:
 
23.8149
 
*/

 



answered May 17, 2021 by avibootz

Related questions

2 answers 223 views
223 views asked May 17, 2021 by avibootz
...