Documentation

AbstractFormatter
in package

AbstractYes

Abstract formatter

Tags
author

Ryan Chouinard rchouinard@gmail.com

copyright

Copyright (c) 2013, Ryan Chouinard

license

MIT License - http://www.opensource.org/licenses/mit-license.php

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

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
uses
bccomp()
uses
AbstractFormatter::divPow()
uses
AbstractFormatter::formatNumber()
uses
AbstractFormatter::normalizeBytes()
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.

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
uses
bcdiv()
uses
bcpow()
used-by
AbstractFormatter::format()
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
uses
AbstractFormatter::normalizePrecision()
used-by
AbstractFormatter::format()
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
uses
bcadd()
uses
bccomp()
uses
filter_var()
used-by
AbstractFormatter::format()
Return values
string

Returns the normalized value.


        
On this page

Search results