+ 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

1st Feb 2019, 12:31 PM
Nik
Nik - avatar
3 odpowiedzi
0
#include<iomanip> double a=20.0; double b=30.0; double c; c=a+b; cout<<fixed<<setprecision(1)<<c;
10th Feb 2019, 6:08 PM
Nik
Nik - avatar
0
I am using c/c++
2nd Feb 2019, 8:44 AM
Nik
Nik - avatar
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
10th Feb 2019, 5:14 PM
Nik
Nik - avatar