减去百分数写出正确的条件

时间:2018-02-27 10:53:37

标签: php

我从DB收到价值 $row['jackpot']它等于5000.00

如何写出正确的条件?

if ($row['jackpot'] < '2000.00') {

      $asd = "2000.00" - $row['jackpot'];
      echo "To participate you are missing".$asd;
}

3 个答案:

答案 0 :(得分:0)

jackpot列的数据类型是什么?如果它是字符串,那么你需要使它浮动,只有<运算符才能在if statement中运行。

$row_jackpot = (float)$row['jackpot'];
if ($row_jackpot  < 2000.00) {

      $asd = 2000.00 - $row_jackpot;
      echo "To participate you are missing".$asd;
}

答案 1 :(得分:0)

如果要保留两位小数,请使用$jackpot = (float)$row['jackpot']; if ($jackpot < 2000) { $asd = number_format(2000 - $jackpot, 2); echo "To participate you are missing".$asd; }

pass

答案 2 :(得分:0)

假设您的$row['jackpot'] = 1000.00;

然后试试这个

if ($row['jackpot'] < 2000.00) {
$asd = number_format(2000.00 - $row['jackpot'], 2);
echo "To participate you are missing " . $asd;
}