Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Higher values in float variable

807578Sep 8 2004 — edited Sep 8 2004
I 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).
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 6 2004
Added on Sep 8 2004
2 comments
222 views