Why does a C floating-point type modify the actual input of 125.1 to 125.099998 on output?

后端 未结 7 1379
耶瑟儿~
耶瑟儿~ 2020-12-12 05:07

I wrote the following program:

 #include
    int main(void)
    {
     float f;
     printf(\"\\nInput a floating-point no.: \");
     scanf(\         


        
7条回答
  •  遥遥无期
    2020-12-12 05:49

    Because its the closest representation of 125.1 , remember that single precision floating point are just 32 bits.

提交回复
热议问题