Usage

Full documentation on how to use the ByteUnitConverter library on your PHP project.

circle-exclamation

ByteUnit

This enum works as a type safety for conversions using ByteUnitConverter utility class, check its documentation to see its usage.

DataUnit

Same as ByteUnit, this is also an enum used for perform conversion between different data units (bytes or bits).

circle-info

Check this Wikipedia articlearrow-up-right to understand what a byte is in terms of bytes and more.

MetricSystem

This is another enum used to convert byte units between different metric systems.

circle-info

Check this Wikipedia articlearrow-up-right to understand what a metric system means as of a general perspective.

ByteUnitConverter

This utility class is used to convert between:

  • Different byte units (KB to MB, TB to GB, etc...)

  • Different data units (kilobytes to kilobits, bytes to bits, etc...)

  • And different metric systems (kilobytes to kibibytes, tebibytes to gigabytes, etc...).

new

Create new instance from bytes:

toBytesFromUnit

Get bytes from unit:

from

Get new instance from value and unit:

numberFormat

circle-info

Reused internally within the library but publicly available.

Format numbers using PHP's number_formatarrow-up-right built-in function but removing thousands separator:

setPrecision

circle-info

Default to 2 as is same as the decimal positions from the output.

circle-exclamation

Customise precision for some conversion operations like divisions:

asRound

Round result to a integer without decimals:

useUnitLabel

Round result to a integer without decimals:

nearestUnit

Convert bytes to their nearest unit on the specified metric system:

getValue

Get the resulting numeric value from the conversion:

getUnit

Get the resulting byte unit as string from the conversion:

to

Convert bytes to byte unit:

circle-info

All byte units from all metric systems available in this library have their own conversion methods for convenience.

usingBytes

Perform conversions using bytes data unit:

circle-info

This library already use bytes as a default data unit.

usingBits

Perform conversions using bits data unit:

__toString

Serialise conversion result to string:

toArray

Serialise conversion result to multidimensional array:

serialize

The ByteUnitConverter utility class can be also serialised/deserialised using PHP serialisation:

Last updated