Documentation

NumberFormat
in package

AbstractYes

Table of Contents

Properties

$number  : string
$precision  : int

Methods

__construct()  : mixed
asFloat()  : float
Returns the number as a float.
asInteger()  : int
Returns the number as a rounded integer with optional rounding mode.
asString()  : string
Returns the number instance as a string with optional decimal places and thousands separator formatting.
isEqualTo()  : bool
Determines whether the "base" number is equal to the specified comparator number.
isGreaterThan()  : bool
Determines whether the "base" number is greater than the specified comparator number.
isGreaterThanOrEqualTo()  : bool
Determines whether the "base" number is greater than or equal to the specified comparator number.
isLessThan()  : bool
Determines whether the "base" number is less than the specified comparator number.
isLessThanOrEqualTo()  : bool
Determines whether the "base" number is less than or equal to the specified comparator number.
isZero()  : bool
Determines whether the "base" number is zero.
castNumberToString()  : string

Properties

Methods

__construct()

public __construct([int|float|string $number = 0 ][, int $precision = 24 ]) : mixed
Parameters
$number : int|float|string = 0

(Optional) The "base" number. Default: 0

$precision : int = 24

(Optional) The number of digits after the decimal place in the result. Default: 24

Tags
throws
NonNumericValue

thrown when number argument is not numeric

asFloat()

Returns the number as a float.

public asFloat() : float
Return values
float —

the number formatted as a float (decimal)

asInteger()

Returns the number as a rounded integer with optional rounding mode.

public asInteger([int $roundingMode = PHP_ROUND_HALF_UP ]) : int
Parameters
$roundingMode : int = PHP_ROUND_HALF_UP

(Optional) The rounding method defined by PHP internal maths constants [PHP_ROUND_HALF_UP (1) | PHP_ROUND_HALF_DOWN (2) | PHP_ROUND_HALF_EVEN (3) | PHP_ROUND_HALF_ODD (4)]. Default: PHP_ROUND_HALF_UP (1)

Return values
int —

the number formatted as an integer (rounded up by default)

asString()

Returns the number instance as a string with optional decimal places and thousands separator formatting.

public asString([int|null $decimalPlaces = null ][, string $thousandsSeparator = '' ]) : string
Parameters
$decimalPlaces : int|null = null

(Optional) The number of decimal places to return (note: this will not round the number, for rounding use the roundToDecimalPlaces method)

$thousandsSeparator : string = ''

(Optional) Thousands separator. Default: empty string (i.e. none)

Tags
throws
InvalidDecimalPlaces

thrown when the decimal places argument is less than zero

Return values
string —

the number formatted as a string

isEqualTo()

Determines whether the "base" number is equal to the specified comparator number.

public isEqualTo(Number|int|float|string $number) : bool
Parameters
$number : Number|int|float|string

the comparator number

Return values
bool —

returns true when the "base" number is equal to the comparator number, or false when the "base" number is less than or greater than the comparator number

isGreaterThan()

Determines whether the "base" number is greater than the specified comparator number.

public isGreaterThan(Number|int|float|string $number) : bool
Parameters
$number : Number|int|float|string

the comparator number

Return values
bool —

returns true when the "base" number is greater than the comparator number, or false when the "base" number is less than or equal to the comparator number

isGreaterThanOrEqualTo()

Determines whether the "base" number is greater than or equal to the specified comparator number.

public isGreaterThanOrEqualTo(Number|int|float|string $number) : bool
Parameters
$number : Number|int|float|string

the comparator number

Return values
bool —

returns true when the "base" number is greater than or equal to the comparator number, or false when the "base" number is less than the comparator number

isLessThan()

Determines whether the "base" number is less than the specified comparator number.

public isLessThan(Number|int|float|string $number) : bool
Parameters
$number : Number|int|float|string

the comparator number

Return values
bool —

returns true when the "base" number is less than the comparator number, or false when the "base" number is greater than or equal to the comparator number

isLessThanOrEqualTo()

Determines whether the "base" number is less than or equal to the specified comparator number.

public isLessThanOrEqualTo(Number|int|float|string $number) : bool
Parameters
$number : Number|int|float|string

the comparator number

Return values
bool —

returns true when the "base" number is less than or equal to the comparator number, or false when the "base" number is greater than the comparator number

isZero()

Determines whether the "base" number is zero.

public isZero() : bool
Return values
bool —

returns true when the "base" number is equal to zero, or false when the "base" number is less than or greater than zero

castNumberToString()

protected castNumberToString(self|int|float|string $number) : string
Parameters
$number : self|int|float|string
Return values
string

        
On this page

Search results