I would like to preg_match a number which is multiple of 6.5.
For example : 1300 % 6.5 == 0
I test this expression but it's wrong
$pattern = '/(6.5)(?:\1)?$/';
$number = 1300;
$matches = preg_match($pattern, $number);
echo $matches;
I would like to preg_match a number which is multiple of 6.5.
For example : 1300 % 6.5 == 0
I test this expression but it's wrong
$pattern = '/(6.5)(?:\1)?$/';
$number = 1300;
$matches = preg_match($pattern, $number);
echo $matches;
Why are you trying to use string manipulation for math ops?
At first I was thinking modulus would be the way to go, but was getting unexpected results, due to the float (6.5).
You could do something like:
$x = (1300 / 6.5);
// If we end up with a decimal at all, then the divisor did not go into the dividend evenly
$divisible = (false !== stripos($x, '.') ? false: true;
I was thinking it would be easier to use is_float
, but it returns true no matter if 6.5 goes into 1300 evenly, because the result is cast as a double due to the 6.5.