You are here

public static function Calculator::compare in Price 3.x

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

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.

7 calls to Calculator::compare()
Calculator::ceil in src/Calculator.php
Calculates the next highest whole value of a number.
Calculator::floor in src/Calculator.php
Calculates the next lowest whole value of a number.
Calculator::round in src/Calculator.php
Rounds the given number.
Price::compareTo in src/Price.php
Compares the current price with the given price.
Price::isZero in src/Price.php
Gets whether the current price is zero.

... See full list

File

src/Calculator.php, line 217

Class

Calculator
Provides helpers for bcmath-based arithmetic.

Namespace

Drupal\price

Code

public static function compare($first_number, $second_number, $scale = 6) {
  self::assertNumberFormat($first_number);
  self::assertNumberFormat($second_number);
  return bccomp($first_number, $second_number, $scale);
}