You are here

public function Price::compareTo in Commerce Core 8.2

Compares the current price with the given price.

Parameters

\Drupal\commerce_price\Price $price: The price.

Return value

int 0 if both prices are equal, 1 if the first one is greater, -1 otherwise.

3 calls to Price::compareTo()
Price::equals in modules/price/src/Price.php
Gets whether the current price is equivalent to the given price.
Price::greaterThan in modules/price/src/Price.php
Gets whether the current price is greater than the given price.
Price::lessThan in modules/price/src/Price.php
Gets whether the current price is lesser than the given price.

File

modules/price/src/Price.php, line 182

Class

Price
Provides a value object for monetary values.

Namespace

Drupal\commerce_price

Code

public function compareTo(Price $price) : int {
  $this
    ->assertSameCurrency($this, $price);
  return Calculator::compare($this->number, $price
    ->getNumber());
}