+ 1

Why my code greater output d1>d2

double d1=100 - 99.99 ; double d2=10 - 9.99 ; the output d1>d2

16th Jul 2021, 9:23 PM
Ali Jdeed
Ali Jdeed - avatar
3 Antworten
+ 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
16th Jul 2021, 10:03 PM
Abhay
Abhay - avatar
+ 2
https://code.sololearn.com/c4193UFx86gq/?ref=app
17th Jul 2021, 1:25 AM
Solo
Solo - avatar
0
Thanks
17th Jul 2021, 4:30 AM
Ali Jdeed
Ali Jdeed - avatar