printf("%.2lf\n",odd); //(1)
printf("%.2lf\n",37.975); //(2)
printf("%.2lf\n",(odd*0.65 -1)*2); //(3)
printf("%.3lf\n",(odd*0.65 -1)*2); //(4)
Below is the output:
30.75
37.98
37.97
37.975
Why the output of expression(3) is not 37.98 ?
I use g++.
This is likely due to floating point rounding errors. The result of
(odd * 0.65 - 1) * 2is likely37.97499999999999or something close to (but less than)37.975. By the usual rounding rules, this is rounded down to37.97in the output.