public static function Calculator::compare in Commerce Core 8.2
Compares the first number to the second number.
Parameters
string $first_number: The first number.
string $second_number: The second number.
int $scale: The maximum number of digits after the decimal place. Any digit after $scale will be truncated.
Return value
int 0 if both numbers are equal, 1 if the first one is greater, -1 otherwise.
13 calls to Calculator::compare()
- BuyXGetY::apply in modules/
promotion/ src/ Plugin/ Commerce/ PromotionOffer/ BuyXGetY.php - Applies the offer to the given entity.
- Calculator::ceil in modules/
price/ src/ Calculator.php - Calculates the next highest whole value of a number.
- Calculator::floor in modules/
price/ src/ Calculator.php - Calculates the next lowest whole value of a number.
- Calculator::round in modules/
price/ src/ Calculator.php - Rounds the given number.
- CalculatorTest::testComparison in modules/
price/ tests/ src/ Unit/ CalculatorTest.php - @covers ::compare
File
- modules/
price/ src/ Calculator.php, line 217
Class
- Calculator
- Provides helpers for bcmath-based arithmetic.
Namespace
Drupal\commerce_priceCode
public static function compare(string $first_number, string $second_number, int $scale = 6) : int {
self::assertNumberFormat($first_number);
self::assertNumberFormat($second_number);
return bccomp($first_number, $second_number, $scale);
}