+ 1
How can I output the sum of two double without loosing any precision of the sum
double a=20.0; double b=30.0; double c; c=a+b; cout<<c; By using this I get 50 as my output but I want that it print the value 50.0 not 50 I don't understand why double loose a precision value
3 odpowiedzi
0
#include<iomanip>
double a=20.0;
double b=30.0;
double c;
c=a+b;
cout<<fixed<<setprecision(1)<<c;
0
I am using c/c++
0
i got the answer you have to use setprecision() function in which you passes the precision value and to use this predefined function you have to include the (iomanip) input/output manipulation library