doukou4066 2019-06-22 16:23
浏览 127

当$ balance高于0.01时,为什么$ if语句中的$ balance不等于0.01? [重复]

This question already has an answer here:

I have a problem with an if statement. The program doesn't go inside the if when it seems that the condition is true.

I tried to change the operator >= to == but it still doesn't work. It works with <= but I need >= and I also can't explain to myself why it's not working.

<?php

$balance = 0.03;      // input 0.03 

if($balance >= 0.02)
{
    $returned = ((floor($balance / 0.02)) * 0.02); // 0.02
    $balance = $balance - $returned;               // 0.03 - 0.02 = 0.01 left
}

echo var_dump($balance) . PHP_EOL;

if($balance >= 0.01)                // why doesnt go in ?
{
    echo "Print Smt ....";
}

Why is the second if not true? Isn't 0.01 equal to 0.01?

</div>
  • 写回答

1条回答 默认 最新

  • dongqing220586 2019-06-22 18:22
    关注

    Because $balance is reassigned value -1.47 which is less than 0.01.

    评论

报告相同问题?

悬赏问题

  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测