You are here

public static function Calculator::subtract in Commerce Core 8.2

Subtracts the second number from the first 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

string The result.

5 calls to Calculator::subtract()
BuyXGetY::clear in modules/promotion/src/Plugin/Commerce/PromotionOffer/BuyXGetY.php
Allows an offer to clean up any modifications done to the given entity.
BuyXGetY::removeQuantities in modules/promotion/src/Plugin/Commerce/PromotionOffer/BuyXGetY.php
Removes the second quantity list from the first quantity list.
BuyXGetY::sliceQuantities in modules/promotion/src/Plugin/Commerce/PromotionOffer/BuyXGetY.php
Takes a slice from the given quantity list.
CalculatorTest::testArithmetic in modules/price/tests/src/Unit/CalculatorTest.php
@covers ::add @covers ::subtract @covers ::multiply @covers ::divide @covers ::compare @covers ::trim
Price::subtract in modules/price/src/Price.php
Subtracts the given price from the current price.

File

modules/price/src/Calculator.php, line 51

Class

Calculator
Provides helpers for bcmath-based arithmetic.

Namespace

Drupal\commerce_price

Code

public static function subtract(string $first_number, string $second_number, int $scale = 6) : string {
  self::assertNumberFormat($first_number);
  self::assertNumberFormat($second_number);
  $result = bcsub($first_number, $second_number, $scale);
  return self::trim($result);
}