PHP unexpected result of float to int type cast

前端 未结 4 1528
说谎
说谎 2020-11-29 08:00

I\'trying to convert a float to an int value in php:

var_dump((int)(39.3 * 100.0)); //Returns 3929 but should be 3930!
var_dump((int)(39.2 * 100.0)); //Retur         


        
4条回答
  •  抹茶落季
    2020-11-29 08:26

    You should have a look at this page: http://php.net/manual/en/language.types.float.php. It describes the pitfalls working with floating point numbers.

提交回复
热议问题