If double b is 0.0000001, then cout << b displays 1e - 07. How to make cout display exactly the decimal fraction in its entirety?

#include <iomanip> ... double a = 0.0000001; cout << setprecision(9) << a;

  • one
    entirely - a loose concept. #include <iomanip> cout << setprecision (15) << b; - pavel
  • one
    @pavel Doesn’t work, in my code there is already setprecision(8) , but output is stable 1e-07 - Ka_ktus
  • one
    then completely code the question as you output. Try to write more than 8. - pavel
  • 3
    cout.setf(ios::fixed); flag set. Something I thought that he himself exhibited. - pavel
  • one
    @pavel Thank you, after setting the flag worked - Ka_ktus

1 answer 1

It is necessary not only setprecision , but also switch to fixed-point format - fixed

 #include <iostream> #include <iomanip> using namespace std; int main() { constexpr double a=1e-9; cout << fixed << setprecision(18) << a << endl; return 0; } 

IDEONE