Home >Backend Development >PHP Tutorial >神奇的PHP 让小弟我找不着北 floatval转 intval 变小

神奇的PHP 让小弟我找不着北 floatval转 intval 变小

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-13 11:55:221020browse

神奇的PHP 让我找不着北 floatval转 intval 变小

//无解了 想不通,求解<br /><br />$c=2700*0.7;<br />$m=1890;<br />var_dump($c<$m); // 两个者的值都是1890 但它却返回 true<br />echo intval($c);// c应该是1890的 但经过intval 它变成了 1889<br />

------解决方案--------------------
$c = 2700*0.7;<br />printf('%.14f', $c); //1889.99999999999977<br />

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn