php - Why can't this be calculated and the result always returns 0?
为情所困
为情所困 2017-05-16 13:15:48
0
2
357
                    <?php
                    $a = $this->item_info['jhl'];
                    $c = intval($a);
                    $b = $this->item_info['price'];
                    $d = intval($b);

                    echo intval((500 / $c) * $d)
                    ; ?>
$this->item_info['jhl']跟$this->item_info['price'];在数据库里面都是数字,如123,456,789这样的数字

为什么计算结果都是0呢

The database field is varchar

为情所困
为情所困

reply all(2)
Ty80

intval(500/intval("789")) = 0
intval(500/intval("345")) = 1,
Same as above

过去多啦不再A梦

When you encounter this kind of problem, print out each variable. The result of using var_dump(),我猜测是因为$c比500大,然后intval()对于浮点数只会取整,比如intval(0.5) is 0

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!