You are here

public function TaxRatePercentage::calculateTaxAmount in Commerce Core 8.2

Calculates the tax amount for the given price.

Parameters

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

bool $included: Whether tax is already included in the price.

Return value

\Drupal\commerce_price\Price The unrounded tax amount.

File

modules/tax/src/TaxRatePercentage.php, line 145

Class

TaxRatePercentage
Represents a tax rate percentage.

Namespace

Drupal\commerce_tax

Code

public function calculateTaxAmount(Price $price, $included = FALSE) {
  $tax_amount = $price
    ->multiply($this->number);
  if ($included) {
    $divisor = Calculator::add('1', $this->number);
    $tax_amount = $tax_amount
      ->divide($divisor);
  }
  return $tax_amount;
}