You are here

public function Price::compareTo in Price 3.x

Same name and namespace in other branches
  1. 8 src/Price.php \Drupal\price\Price::compareTo()
  2. 2.0.x src/Price.php \Drupal\price\Price::compareTo()
  3. 2.x src/Price.php \Drupal\price\Price::compareTo()
  4. 3.0.x src/Price.php \Drupal\price\Price::compareTo()

Compares the current price with the given price.

Parameters

\Drupal\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 src/Price.php
Gets whether the current price is equivalent to the given price.
Price::greaterThan in src/Price.php
Gets whether the current price is greater than the given price.
Price::lessThan in src/Price.php
Gets whether the current price is lesser than the given price.

File

src/Price.php, line 167

Class

Price
Provides a value object for monetary values.

Namespace

Drupal\price

Code

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