MathUtility

class \TYPO3\CMS\Core\Utility\MathUtility

Class with helper functions for mathematical calculations

Table of Contents

Methods

calculateWithParentheses()  : string
Calculates the input with parenthesis levels
calculateWithPriorityToAdditionAndSubtraction()  : float|string
Calculates the input by +,-,*,/,%,^ with priority to + and -
canBeInterpretedAsFloat()  : bool
Tests if the input can be interpreted as float.
canBeInterpretedAsInteger()  : bool
Tests if the input can be interpreted as integer.
forceIntegerInRange()  : int
Forces the integer $theInt into the boundaries of $min and $max. If the $theInt is FALSE then the $defaultValue is applied.
isIntegerInRange()  : bool
Checks whether the given number $value is an integer in the range [$minimum;$maximum]

Methods

calculateWithParentheses()

Calculates the input with parenthesis levels

public static calculateWithParentheses(string $string) : string

Parameters

$string : string

Input string, eg "(123 + 456) / 789 - 4

Tags

see
calculateWithPriorityToAdditionAndSubtraction()
see
ContentObjectRenderer::stdWrap()

Return values

string —

Calculated value. Or error string.

calculateWithPriorityToAdditionAndSubtraction()

Calculates the input by +,-,*,/,%,^ with priority to + and -

public static calculateWithPriorityToAdditionAndSubtraction(string $string) : float|string

Parameters

$string : string

Input string, eg "123 + 456 / 789 - 4

Tags

see
MathUtility::calculateWithParentheses()

Return values

float|string —

Calculated value. Or error string.

canBeInterpretedAsFloat()

Tests if the input can be interpreted as float.

public static canBeInterpretedAsFloat(mixed $var) : bool

Note: Float casting from objects or arrays is considered undefined and thus will return false.

Parameters

$var : mixed

Any input variable to test

Tags

see
http://www.php.net/manual/en/language.types.float.php,

section "Formally" for the notation

Return values

bool —

Returns TRUE if string is a float

canBeInterpretedAsInteger()

Tests if the input can be interpreted as integer.

public static canBeInterpretedAsInteger(mixed $var) : bool

Note: "0" will return true while any other number with a leading 0 (including multiple zeroes) will be false.

Note: Integer casting from objects or arrays is considered undefined and thus will return false.

Parameters

$var : mixed

Any input variable to test

Tags

see
https://php.net/manual/en/language.types.integer.php#language.types.integer.casting.from-other

Return values

bool —

Returns TRUE if string is an integer

forceIntegerInRange()

Forces the integer $theInt into the boundaries of $min and $max. If the $theInt is FALSE then the $defaultValue is applied.

public static forceIntegerInRange(mixed $theInt, int $min[, int $max = 2000000000 ][, int $defaultValue = 0 ]) : int

Parameters

$theInt : mixed

Input value - will be cast to int if non-integer value is passed.

$min : int

Lower limit

$max : int = 2000000000

Higher limit

$defaultValue : int = 0

Default value if input is FALSE.

Return values

int —

The input value forced into the boundaries of $min and $max

isIntegerInRange()

Checks whether the given number $value is an integer in the range [$minimum;$maximum]

public static isIntegerInRange(mixed $value, int $minimum, int $maximum) : bool

Parameters

$value : mixed

Integer value to check. If not an integer this method always returns false.

$minimum : int

Lower boundary of the range

$maximum : int

Upper boundary of the range

Return values

bool
On this page