PHP 隐式转换(自动装换)和 bc 精度函数
<?php echo 1+true; //true -> 1 echo '<hr />'; echo 1+false; //false -> 0 echo '<hr />'; echo 1.1+false; echo '<hr />'; echo 1.1+true; echo '<hr />'; echo 1+null; //null -> 0 echo '<hr />'; echo 1 + 'a'; //不是以合法数字开始直接转换成0 echo '<hr />'; echo 1 + 'true'; //这里的true 是字符串这里这里 转转中成转中成成 0 echo '<hr />'; echo 1 + '43king'; //这里会自动截取到字符为止 echo '<hr />'; echo 1+'3qu2e1nn4'; //只会截取到第一个数字 echo '<hr />'; echo 1+'8.8abv'; echo '<hr />'; echo 1+'3e2abc'; echo '<hr />'; echo '1.234561' + '2.222222'; echo '<hr />' ; echo 1 + '2.333333'; echo "<hr />"; echo 1.23 + 5.6666666; echo "<hr />"; echo true; // true -> 1 echo "<hr />"; echo false; // 直接输出false 转成 空字符 echo 'a',false,'b'; echo "<hr />"; echo null; // 直接输出NULL 转成 空字符 echo "A",NULL,"B"; echo "<hr />"; $var=1; $var=-123; $var=0;//false $var=1.2; $var=0.0;//false $var='';//false $var="";//false $var=" "; $var="0";//false $var='0.0'; $var='false'; $var=null;//false $var=array();//false $var=array(1,2,3,0,'',null); $var=fopen('test_6.php','r'); $var=new stdClass(); if($var){ echo 'true'; }else{ echo 'false'; } echo "<hr />"; $a = 0.1; $b = 0.7; var_dump(($a + $b) == 0.8); //false echo "<hr />"; //解决方法: $a = 0.1; $b = 0.7; var_dump(bcadd($a,$b,2) == 0.8); echo "<hr />"; $f = 0.58; var_dump(intval($f * 100)); echo "<hr />"; //解决方法: $f = 0.58; var_dump(bcmul($f,100)); echo 1.35 + bcmul($f,100);
相关推荐
MXstudying 2020-09-05
WasteLand 2020-09-15
<?php. if (!empty($_POST)) {. $data1 = $_POST["data1"];$data2 = $_POST["data2"];$fuhao = $_POST["fuh
mathchao 2020-09-15
zyyjay 2020-11-09
xuebingnan 2020-11-05
samtrue 2020-11-22
stefan0 2020-11-22
yifangs 2020-10-13
songshijiazuaa 2020-09-24
hebiwtc 2020-09-18
天步 2020-09-17
83911535 2020-11-13
whatsyourname 2020-11-13
zhouyuqi 2020-11-10
Noneyes 2020-11-10
mathchao 2020-10-28
王志龙 2020-10-28