3

I am try to print a double variable a like this.

double a;
//some statements for a
LOG(INFO) << a;

How can I print a using full precision?

chain ro
  • 737
  • 2
  • 10
  • 21

1 Answers1

3

You should try

#include <iomanip>      // std::setprecision

double a = 3.141592653589793238;
LOG(INFO) << std::fixed << std::setprecision( 15 ) << a;

If that doesn't work you can convert it to an std::string and use std::stringstream

#include <sstream>      // std::stringstream 
#include <iomanip>      // std::setprecision 

double a = 3.141592653589793238;
std::stringstream ss;
ss << std::fixed << std::setprecision( 15 ) << a;
LOG(INFO) << ss.str();

Alternatively, if you want full precision you can use one of the above with this answer.

The first method is more than likely to be the most efficient way to do it.

Community
  • 1
  • 1