Number
in package
Number helper
Table of Contents
Constants
- ACCOUNTING_FORMAT = ['decimals' => 3, 'decimals_separator' => '.', 'thousands_separator' => ',']
- Default format values
- ACCOUNTING_FORMAT_NAME = 'accounting'
- BOOLEAN_TEXT_VALUES = ['true', 'false', '0', '1', 'on', 'off', 'yes', 'no']
- Text values which may convert to boolean
- DEFAULT_FORMAT = ['decimals' => 2, 'decimals_separator' => '.', 'thousands_separator' => ',']
- Default format values
- DEFAULT_FORMAT_NAME = 'default'
- FORMATS_LIST = ['default' => Self::DEFAULT_FORMAT, 'accounting' => Self::ACCOUNTING_FORMAT]
- Formats list
Properties
- $formats : array<string|int, mixed>
- Number formats
- $format : array<string|int, mixed>|null
- Number format
Methods
- format() : int|float
- Format number
- getFormat() : array<string|int, mixed>
- Get format options
- getFraction() : float
- Get number fraction
- getInteger() : int
- Get integer value
- getNumericValue() : int|float
- Return 0 if variable is not number
- isBoolean() : bool
- Return true if text is boolean value
- isFloat() : bool
- Return true if variable is float
- isNumber() : bool
- Return true if variable is number
- resolveFormat() : array<string|int, mixed>
- Resolve format
- sanitizeNumber() : float
- Sanitize number
- setFormat() : void
- Set number format
- toBoolean() : bool
- Convert text to bool value
- toNumber() : mixed
- Type cast to int, foat, bool
- resolveFormatArray() : array<string|int, mixed>
- Resolbe format array
Constants
ACCOUNTING_FORMAT
Default format values
public
mixed
ACCOUNTING_FORMAT
= ['decimals' => 3, 'decimals_separator' => '.', 'thousands_separator' => ',']
ACCOUNTING_FORMAT_NAME
public
mixed
ACCOUNTING_FORMAT_NAME
= 'accounting'
BOOLEAN_TEXT_VALUES
Text values which may convert to boolean
public
mixed
BOOLEAN_TEXT_VALUES
= ['true', 'false', '0', '1', 'on', 'off', 'yes', 'no']
DEFAULT_FORMAT
Default format values
public
mixed
DEFAULT_FORMAT
= ['decimals' => 2, 'decimals_separator' => '.', 'thousands_separator' => ',']
DEFAULT_FORMAT_NAME
public
mixed
DEFAULT_FORMAT_NAME
= 'default'
FORMATS_LIST
Formats list
public
mixed
FORMATS_LIST
= ['default' => Self::DEFAULT_FORMAT, 'accounting' => Self::ACCOUNTING_FORMAT]
Properties
$formats
Number formats
protected
static array<string|int, mixed>
$formats
= []
$format
Number format
private
static array<string|int, mixed>|null
$format
= null
Methods
format()
Format number
public
static format(int|float $number[, string|null|array<string|int, mixed> $format = null ]) : int|float
Parameters
- $number : int|float
- $format : string|null|array<string|int, mixed> = null
Return values
int|floatgetFormat()
Get format options
public
static getFormat() : array<string|int, mixed>
Return values
array<string|int, mixed>getFraction()
Get number fraction
public
static getFraction(mixed $value) : float
Parameters
- $value : mixed
Return values
floatgetInteger()
Get integer value
public
static getInteger(mixed $value) : int
Parameters
- $value : mixed
Return values
intgetNumericValue()
Return 0 if variable is not number
public
static getNumericValue(mixed $value) : int|float
Parameters
- $value : mixed
Return values
int|floatisBoolean()
Return true if text is boolean value
public
static isBoolean(string $text) : bool
Parameters
- $text : string
Return values
boolisFloat()
Return true if variable is float
public
static isFloat(mixed $variable) : bool
Parameters
- $variable : mixed
Return values
boolisNumber()
Return true if variable is number
public
static isNumber(mixed $variable) : bool
Parameters
- $variable : mixed
Return values
boolresolveFormat()
Resolve format
public
static resolveFormat(string|array<string|int, mixed>|null $format) : array<string|int, mixed>
Parameters
- $format : string|array<string|int, mixed>|null
Return values
array<string|int, mixed>sanitizeNumber()
Sanitize number
public
static sanitizeNumber(mixed $number[, int $decimals = 2 ]) : float
@param mixed $number
Parameters
- $number : mixed
- $decimals : int = 2
Return values
floatsetFormat()
Set number format
public
static setFormat(mixed $format) : void
Parameters
- $format : mixed
toBoolean()
Convert text to bool value
public
static toBoolean(mixed $text) : bool
Parameters
- $text : mixed
Return values
booltoNumber()
Type cast to int, foat, bool
public
static toNumber(mixed $number) : mixed
Parameters
- $number : mixed
resolveFormatArray()
Resolbe format array
private
static resolveFormatArray(array<string|int, mixed> $format) : array<string|int, mixed>
Parameters
- $format : array<string|int, mixed>