Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,892 questions

51,823 answers

573 users

How to print a double value with full precision using cout in C++

3 Answers

0 votes
#include <iostream>
 
int main() {
    double f = 3.141592653589793;
    
    std::cout.unsetf(std::ios::floatfield);             
    std::cout.precision(16);
    std::cout << f << "\n";
 
    std::cout.precision(14);
    std::cout << f << "\n";
   
    std::cout.setf(std::ios::fixed, std:: ios::floatfield); 
    std::cout << f << '\n';
}

  
  
/*
run:
  
3.141592653589793
3.1415926535898
3.14159265358979
 
*/
    

 



answered Jan 8, 2022 by avibootz
edited Jun 5, 2024 by avibootz
0 votes
#include <iostream>
#include <iomanip>

int main() {
    std::cout << std::setprecision(16) << 3.141592653589793 << std::endl;
}

    
          
/*
run:
       
3.141592653589793

*/

 



answered Jun 5, 2024 by avibootz
0 votes
#include <iostream>
#include <numbers>
#include <format>
 
int main()
{
    std::cout << std::format("{}", std::numbers::pi_v<double>); // C++ 20
}
 
 
/*
run:

3.141592653589793 

*/

 



answered Jun 5, 2024 by avibootz

Related questions

1 answer 159 views
2 answers 198 views
1 answer 76 views
1 answer 120 views
2 answers 104 views
104 views asked Feb 21, 2022 by avibootz
1 answer 190 views
1 answer 153 views
...