가능한 중복 서로 다른 결과를 얻을 수 :
PHP unexpected result of float to int type cast
int((0.1+0.7)*10) = 7 in several languages. How to prevent this?추가 분수의 수는 PHP에
누군가가 나에게 이것을 설명 할 수 있습니다 ???
<?php
echo (int) ((0.1 + 0.7)*10);//displays an output: `7`
?>
나는 8
를보기 위해 기다리고 있었다 그러나 나는 7
있어 -이 동작을 설명해주십시오.
PHP
의 특별한 기능입니까? 또는 PHP
의 정수 유형을 이해하지 못 했습니까?
감사합니다.
왜 아래로 투표합니까? 설명해 주시겠습니까? –
[int ((0.1 + 0.7) * 10) = 7의 복제본이 여러 언어로 가능합니다. 이것을 방지하는 방법?] (http://stackoverflow.com/questions/6439140/int0-10-710-7-in-several-languages-how-to-prevent-this) 그리고 아마도 [컴퓨터가 부동 소수점 연산을 수행하는 방법 ?] (http://stackoverflow.com/questions/6033184/how-computer-does-floating-point-arithmetic) –
거기에 내부 프리젠 테이션이 다릅니다. PHP 매뉴얼 읽기 [page] (http://php.net/manual/en/language.types.float.php) –