PHP code example of scriptfusion / byte-formatter

1. Go to this page and download the library: Download scriptfusion/byte-formatter library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

scriptfusion / byte-formatter example snippets


(new ByteFormatter)->format(0x80000);

(new ByteFormatter)->setBase(Base::DECIMAL)->format(500000);

(new ByteFormatter)->format(0x80233);

(new ByteFormatter)->setPrecision(2)->format(0x80233);

(new ByteFormatter)->setPrecision(2)->format(0x80200);

(new ByteFormatter)->setPrecision(2)->disableAutomaticPrecision()->format(0x80200);

(new ByteFormatter)->setPrecision(2)->format(0x80233, 4);

(new ByteFormatter)->setFormat('%v%u')->format(0x80000);

(new ByteFormatter)->setFixedExponent(1)->format(1024 * 1024);

(new ByteFormatter(new SymbolDecorator(SymbolDecorator::SUFFIX_METRIC)))
    ->format(0x80000)

(new ByteFormatter(new SymbolDecorator(SymbolDecorator::SUFFIX_NONE)))
    ->format(0x80000)

(new ByteFormatter(new SymbolDecorator(SymbolDecorator::SUFFIX_NONE)))
    ->format(512)

(new ByteFormatter(
    (new SymbolDecorator(SymbolDecorator::SUFFIX_NONE))
        ->alwaysShowUnit()
))
    ->format(512)

(new ByteFormatter(new NameDecorator))
    ->format(0x80000)

(new ByteFormatter(new NameDecorator))
    ->setBase(Base::DECIMAL)
    ->format(500000)