Insideall / dfp-prebid-lineitems

A PHP script to setup and update your Prebid Line Items in DFP
19 stars 11 forks source link

bccomp error in scripts/Buckets.php #12

Closed TiagoValdo closed 5 years ago

TiagoValdo commented 5 years ago

As stated by php docs, the bccomp function takes two strings to perform the comparison. The code is using numeric values directly, which causes some values to fail the comparison and therefore, some line items will be missing.

to fix that, the bccomp functions need to have the operands converted to strings:

for ($i = $value['min']; bccomp(sprintf('%F', $i), sprintf('%F', $value['max']), $precision) <= 0; $i += $value['increment']) {
    if ($i > 0 && 0 !== bccomp(sprintf('%F', $i), sprintf('%F', $lastValue), 2)) {
        array_push($buckets, sprintf("%0.{$precision}f", $i));
    }
    $lastValue = $i;
}
gchicoye commented 5 years ago

You need to install bccomp https://www.php.net/manual/en/bc.installation.php