+ 1
Why my code greater output d1>d2
double d1=100 - 99.99 ; double d2=10 - 9.99 ; the output d1>d2
3 Answers
+ 5
Write this and you will understand the problem.
cout.precision(17);
cout<<d1<<endl<<d2;
Basically you can't do much about it . To store floating values as binary value there is some rounding off of value after some digits due to which there is some precision loss .
Maybe there are libraries out there that can fix the value at after some decimal digits but i am not aware of any .
Additionally take a look at this thread for other ways to print the full double value .
https://stackoverflow.com/questions/554063/how-do-i-print-a-double-value-with-full-precision-using-cout
+ 2
https://code.sololearn.com/c4193UFx86gq/?ref=app
0
Thanks