Higher values in float variable
807578Sep 8 2004 — edited Sep 8 2004I have this program:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
int main()
{
float B;
printf("Size of int %d\n",sizeof(int));
printf("Size of float %d\n",sizeof(float));
B = 16777220 ;
printf("value in float %e and %d AND %x\n",B, (int) B, (int)B);
}
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
It's outout is as follows:
Size of int 4
Size of float 4
value in float 1.677722e+07 and 16777220 AND 1000004
if you observe, it prints 16777220 instead of 16777219...
How can I retain the original value in float variable? Assuming I don't have the option of changing the variable from float to double (I should not use double variable).