Skip to content

Commit

Permalink
Fixed multipleOf
Browse files Browse the repository at this point in the history
  • Loading branch information
sorinsarca committed Jun 7, 2020
1 parent b42b7fd commit 58d33ae
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/ValidatorHelper.php
Expand Up @@ -126,6 +126,10 @@ public function isMultipleOf($number, $divisor): bool
if (!$this->useBCMath) {
return 0 == $number - $divisor * (int)($number / $divisor);
}

$number = number_format($number, $this->scale, '.', '');
$divisor = number_format($divisor, $this->scale, '.', '');

$x = bcdiv($number, $divisor, 0);
$x = bcmul($divisor, $x, $this->scale);
$x = bcsub($number, $x, $this->scale);
Expand Down

2 comments on commit 58d33ae

@bogdangrab
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you merge this fix?
There is an issue with some floats that converts a decimal number to an exponential expression that in turn will break execution when calling bcdiv or any of the subsequent BCMath functions.

@sorinsarca
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bogdangrab Changes should now be in version 1.0.19

Please sign in to comment.