0

I have a small function to compare floating point number

  public function DecoupagePilierI($SCORE_PILIER_I)
  {
    $PILIER_I_MIN = $this->seuilRepository->findOneBy(["name" => 'PILIER_I_MIN'])->getValue();
    $PILIER_I_MAX = $this->seuilRepository->findOneBy(["name" => 'PILIER_I_MAX'])->getValue();
    if ($SCORE_PILIER_I <= $PILIER_I_MIN) {
      return 3;
    }
    if (($PILIER_I_MIN < $SCORE_PILIER_I) && ($SCORE_PILIER_I <= $PILIER_I_MAX)) {
      return 4;
    }
    if ($SCORE_PILIER_I > $PILIER_I_MAX) {
      return 5;
    }
  }

In my case $SCORE_PILIER_I = $PILIER_I_MIN = 3.4

Why i'm getting $SCORE_PILIER_I <= $PILIER_I_MIN = false ?

Khaled Boussoffara
  • 1,567
  • 2
  • 25
  • 53
  • This is not specific to php or symfony- see the link above – ADyson Aug 03 '22 at 11:39
  • Welcome to the [IEEE Standard for Floating-Point Arithmetic (IEEE 754)](https://en.wikipedia.org/wiki/IEEE_754). This is how floating point numbers work in every language that uses such spec, you simply can't test for equality that way. – Álvaro González Aug 03 '22 at 11:39

0 Answers0