I had a float varible that was 130.975006 and I printed it out as %.2f, I were expacting to see 130.97 and for some reason I got 130.98 and only when I switched it to a double varible I got the 130.97
why does, when I want to print out a floating point number with only two numbers after the decimal point it get's rounded up, but the same thing doesn't happen to a double variable, and is there a way to bypass it? for exmple why does the output of this code: `
#include <stdio.h>
int main(){
float num1 = 130.975000;
double num2 = 130.975000;
printf("float is %.2f,double is %.2lf",num1,num2);
return 0;
}
`
is: "float is 130.98,double is 130.97"
and how can I print out a float varible with only two numbers after the decimal point without rounding the number?