AbstractFormatter
in package
Abstract formatter
Tags
Table of Contents
Properties
- $base : int
- $precision : int
- $suffixes : array<string|int, mixed>
Methods
- format() : string
- Format input into a human-friendly string for display.
- getPrecision() : int
- Get the currently configured default precision value.
- setPrecision() : AbstractFormatter
- Set the default precision value.
- divPow() : string
- Shortcut method to divide a dividend by the result of a power operation.
- formatNumber() : string
- Format a number with the given suffix and precision.
- normalizeBytes() : string
- Normalize bytes value into a usable value.
- normalizePrecision() : int
- Normalize precision value into a usable value.
Properties
$base
protected
int
$base
$precision
protected
int
$precision
= 2
$suffixes
protected
array<string|int, mixed>
$suffixes
= array()
Methods
format()
Format input into a human-friendly string for display.
public
format(int|string $bytes[, int $precision = null ]) : string
Parameters
- $bytes : int|string
-
Integer or string representing the number of bytes.
- $precision : int = null
-
Number of significant digits to include in the formatted output. Defaults to 2.
Tags
Return values
string —Returns a human-friendly formatted string.
getPrecision()
Get the currently configured default precision value.
public
getPrecision() : int
Return values
int —Returns the currently configured precision.
setPrecision()
Set the default precision value.
public
setPrecision(int $precision) : AbstractFormatter
Parameters
- $precision : int
-
An integer between 0 and 10.
Tags
Return values
AbstractFormatter —Returns an instance of self for method chaining.
divPow()
Shortcut method to divide a dividend by the result of a power operation.
protected
divPow(int|string $dividend, int $base, int $power) : string
The return value will be a string representation of the result. This is due to the BCMath library and so we can work with very large integers.
Parameters
- $dividend : int|string
-
The dividend to use in the division operation.
- $base : int
-
The base for the power operation.
- $power : int
-
The power $base should be raised by.
Tags
Return values
string —Returns the result of the operations.
formatNumber()
Format a number with the given suffix and precision.
protected
formatNumber(int|float $float, string $suffix[, int $precision = null ]) : string
Parameters
- $float : int|float
-
The number to format.
- $suffix : string
-
The suffix to attach.
- $precision : int = null
-
The number of significant digits to include.
Tags
Return values
string —Returns the formatted string.
normalizeBytes()
Normalize bytes value into a usable value.
protected
normalizeBytes(int|float|string $bytes) : string
The resulting value is a string representation of the bytes value. This is done by the BCMath library so we can work with very large integer values.
Parameters
- $bytes : int|float|string
-
The bytes value.
Tags
Return values
string —Returns the normalized value.
normalizePrecision()
Normalize precision value into a usable value.
protected
normalizePrecision(int $precision) : int
The resulting value is an integer value between 0 and 10.
Parameters
- $precision : int
-
The precision value.
Tags
Return values
int —Returns the normalized value.