nice printing 0 not -4.44e-14

G

Gary Wessle

Hi

I am expecting to get "0" (that is zero) printed but getting
"-2.7311e-14" almost zero. not nice for printing.

double a = \*...code calculations ...*\
some times a becomes a real, integer or natural number and I like it
to print in nice human read format.

cout << setw(20) << left << setprecision(5) << a;

thank you
 
M

Mike Wahler

Gary Wessle said:
Hi

I am expecting to get "0" (that is zero) printed but getting
"-2.7311e-14" almost zero. not nice for printing.

double a = \*...code calculations ...*\
some times a becomes a real, integer or natural number and I like it
to print in nice human read format.

cout << setw(20) << left << setprecision(5) << a;

std::cout << std::fixed
<< std::setprecision(5)
<< std::left
<< std::setw(20)
<< a;

However, for numeric output, I generally prefer
std::right over std::left

-Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top