You are here

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

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

Assert that the given number is a numeric string value.

Parameters

string $number: The number to check.

Throws

\InvalidArgumentException Thrown when the given number is not a numeric string value.

8 calls to Calculator::assertNumberFormat()
Calculator::add in src/Calculator.php
Adds the second number to the first number.
Calculator::compare in src/Calculator.php
Compares the first number to the second number.
Calculator::divide in src/Calculator.php
Divides the first number by the second number.
Calculator::multiply in src/Calculator.php
Multiplies the first number by the second number.
Calculator::round in src/Calculator.php
Rounds the given number.

... See full list

File

src/Calculator.php, line 256

Class

Calculator
Provides helpers for bcmath-based arithmetic.

Namespace

Drupal\price

Code

public static function assertNumberFormat($number) {
  if (is_float($number)) {
    throw new \InvalidArgumentException(sprintf('The provided value "%s" must be a string, not a float.', $number));
  }
  if (!is_numeric($number)) {
    throw new \InvalidArgumentException(sprintf('The provided value "%s" is not a numeric value.', $number));
  }
}