0

Just working on a really basic php script (inside a laravel controller).

For some reason, one of my testing conditions won't work on numeric values. The "if" statement is as simple as a basic comparison between two numeric values.

I would like to test the difference between two numeric and, when different, apply a correction treatment.

So far, the script is runing aggainst 100K raws and only 3 specific raws of them show up as different but are actually not.

Here is my function :

  public function listeEcheancesErronnees(){

$echeancesErronnees = array();

$ecritures = Ecriture::getMainColumns()
  ->where('ECRNO','>',129000)
  ;

foreach ($ecritures as $ligneEcriture) {
  $totalEcheances = 0;
  $totalEcriture = 0;

  foreach (Echeance::getByEcrnoEcrlg($ligneEcriture->DOS,
        $ligneEcriture->ECRNO,
        $ligneEcriture->ECRLG)
      as $echeance) {
    $totalEcheances = $totalEcheances + $echeance->MTSIGNE;

  }

  if ($totalEcheances <> 0) {
    $totalEcriture = $totalEcriture + $ligneEcriture->MTSIGNE;

    if (floatval($totalEcheances) !== floatval($totalEcriture)) {
      //echo (floatval($totalEcheances) !== floatval($totalEcriture));
      echo gettype(floatval($totalEcheances));
      echo gettype(floatval($totalEcriture));
      echo gettype($totalEcheances);
      echo gettype($totalEcriture);
      echo $totalEcheances;
      echo $totalEcriture."<br>";
      var_dump(mb_ord($totalEcheances, "UTF-8"));
      var_dump(mb_ord($totalEcriture, "UTF-8"));
      echo "<br>";

      $echeancesErronnees[] = ['ligne' => $ligneEcriture,
        'totalEcheances' => floatval($totalEcheances),
        'totalEcriture' => floatval($totalEcriture)
      ];

    }

  }

Here is the result of my "echo"s :

doubledoubledoubledouble33.9833.98
int(51) int(51)
doubledoubledoubledouble-33.98-33.98
int(45) int(45)
doubledoubledoubledouble9.89.8
int(57) int(57)

As you can see, both tested variables seem to be of same values and same types and I can get to know why the "if condition" is then true?

Thx for your help

  • 1
    can you paste `var_dump` for raw values of `$totalEcheances` and `$totalEcriture` ?? – Daredzik Sep 06 '21 at 09:32
  • @Daredzik, here is the result of var_dumpl : float(-33.98) float(9.8) float(9.8) – Bill Ballois Sep 06 '21 at 09:55
  • However, @CBroe, this does answer my question! That was excatly the problem on float comparison between one value and one result of calculation! Thx a lot for your answers guys! – Bill Ballois Sep 06 '21 at 09:57

0 Answers0