Shawn Brar
Shawn Brar

Reputation: 1420

Print double data type with a precision upto 4 decimal places - Armadillo

I am trying to use the armadillo library in c++ to do the following.

Whenever I print out a matrix (arma::mat), it is always printed in the following form:-

1.0594e+03   1.0439e+04   0.3425e+04
1.0232e+03  12.0319e+04   0.1225e+04
11.5044e+03   1.231e+04   0.3424e+04

I wanted to know if there was a way to remove the e+04 and actually printing out the whole numbers like:-

 1059.4   1043.9  3425.0
1023.23 120319.0  1225.0
11504.4   1231.0  3424.0

Upvotes: 0

Views: 336

Answers (1)

Frodyne
Frodyne

Reputation: 3973

A bit of googeling takes me to http://arma.sourceforge.net/docs.html#raw_print which says:

Similar to the .print() member function, with the difference that no formatting of the output is done; the stream's parameters such as precision, cell width, etc. can be set manually

And shows this example:

mat A = randu<mat>(5,5);

cout.precision(11);
cout.setf(ios::fixed);

A.raw_print(cout, "A:");

If that is what you are looking for, then you can study further here: https://en.cppreference.com/w/cpp/io/ios_base/fmtflags to see other formatting parameters you can set.

Upvotes: 4

Related Questions