PHP cast to integer returns wrong value
问题 Have a look at this my friend and tell me I'm not crazy... echo (int) (9.45 * 100); // gives 944 echo (int) 945; // gives 945 I don't understand why the first instruction would return 944!???? Is this a known php issue? help is appreciated as always! 回答1: According to PHP documentation (http://php.net/manual/en/language.types.integer.php) When converting from float to integer, the number will be rounded towards zero. That's why you are getting 944. 回答2: Floating point numbers have limited