fork download
  1. #include <iostream>
  2. #include <limits>
  3. #include <iomanip>
  4.  
  5. template <typename T>
  6. unsigned get_max_precision()
  7. {
  8. return std::numeric_limits<T>::max_digits10 + 1;
  9. }
  10.  
  11. int main()
  12. {
  13. float a = 0.7;
  14. double b = 0.7;
  15.  
  16. std::cout << std::setprecision(get_max_precision<double>());
  17. std::cout << "a is " << a << "\nb is " << b << '\n';
  18. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
a is 0.699999988079071045
b is 0.699999999999999956