#include <stdio.h>
#include <math.h>
int main(){
printf("Rounded value of 6*0.95*0.25 = %.2f\n", round(6*0.95*0.25*100)/100);
printf("Rounded value of 1.425 = %.2f\n", round(1.425*100)/100);
}
I have a suspicion that it is to do with the accuracy of the doubles and respective arithmetic, but how I can solve this (such that 6*0.95*0.25 which is 1.425 will round to 1.43) I have no idea....
(I am using the GNU compiler latest version (1.7 something))
help appreciated
I am trying to round to 2 d.p.
The following is the output:
Rounded value of 6*0.95*0.25 = 1.42
Rounded value of 1.425 = 1.43
( https://onlinegdb.com/r1ZtZ2lCW )
I want
Rounded value of 6*0.95*0.25 = 1.43
Rounded value of 1.425 = 1.43