Automattic\WooCommerce\StoreApi\Utilities
QuantityLimits::is_multiple_of
Checks if a number is a multiple of another number.
Method of the class: QuantityLimits{}
No Hooks.
Returns
true|false.
Usage
// protected - for code of main (parent) or child class $result = $this->is_multiple_of( $number, $multiple_of );
- $number(int|float) (required)
- The number to check.
- $multiple_of(int|float) (required)
- The multiple.
QuantityLimits::is_multiple_of() QuantityLimits::is multiple of code WC 10.9.1
protected function is_multiple_of( $number, $multiple_of ) {
if ( 0 >= $multiple_of ) {
return false;
}
$division_result = $number / $multiple_of;
// Use tolerance for floating-point comparison to handle precision errors.
// Example: 0.3 / 0.1 = 2.9999999999999996 instead of exactly 3.0 due to floating-point precision.
return abs( $division_result - round( $division_result ) ) < 0.0001;
}