Common operations and tools related with numbers
| package | Default |
|---|
forceNumeric(mixed $value,string $valueName = '',string $errorMessage = 'must be numeric'): void
| Throws |
|
|---|
mixedA value to check
stringThe name of the value to be shown at the beginning of the exception message
stringThe rest of the exception message
forcePositiveInteger(mixed $value,string $valueName = '',string $errorMessage = 'must be a positive integer'): void
| Throws |
|
|---|
mixedA value to check
stringThe name of the value to be shown at the beginning of the exception message
stringThe rest of the exception message
generateRandomInteger(integer $min,integer $max): integer
| Throws |
|
|---|
integerlowest possible value (negative values are allowed)
integerhighest possible value (negative values are allowed)
integerA random integer value between min and max
getNumeric(mixed $value,string $decimalDivider = ''): \org\turbocommons\src\main\php\utils\number
mixedA value to convert to a number
stringThe decimal divider to use. Possible values are '.' and ','. If not provided, it will be auto-detected.
\org\turbocommons\src\main\php\utils\numberThe numeric type representation from the given value. For example, a string '0001' will return 1
isInteger(mixed $value): boolean
mixedA value to check
booleantrue if the given value is a numeric integer or represents a numeric integer value, false otherwise
isNumeric(mixed $value,string $decimalDivider = ''): boolean
mixedA value to check.
stringThe decimal divider to use. Possible values are '.' and ','. If not provided, it will be auto-detected.
booleantrue if the given value is numeric, false otherwise.
NON_NUMERIC_ERROR
| constant | string |
|---|---|