I'm facing the below problem in C & C++. The following code snippet is giving me incorrect result.
#include<stdio.h>
void main()
{
double a=40.48;
int b=a*10000;
printf("The value of b : %d",b);
}
The output of the above code snippet is 404799 where I expect it to be 404800. Can you please help me explain why it is ? And guide me with necessary corrections.
The above code snippet gives me correct results if I try with other values of variable a.
For example:
#include<stdio.h>
void main()
{
double a=40.49;
int b=a*10000;
printf("The value of b : %d",b);
}
The output of the above code snippet is 404900 which is absolutely correct.
So please enlighten me why the calculation is going wrong with value 40.48.
Thanks in advance.