1. Go to this page and download the library: Download penangites/number 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/ */
penangites / number example snippets
use Penangites\Number\Number;
use Penangites\Number\Percentage;
Number::of('19.90')
->tax(Percentage::fromPercent('6'))
->toString(); // "21.094" — exact, no rounding until you ask
Number::of('19.90')
->tax(Percentage::fromPercent('6'))
->round(2)
->toString(); // "21.09"
Number::of('19.90'); // strings are exact — prefer them
Number::of(100); // integers are exact
Number::of(1.5); // floats accepted, stored as the double really holds them
Number::of('1.0E-5'); // scientific notation is expanded exactly
Number::of(0.1 + 0.2)->toString(); // "0.30000000000000004" — never was 0.3
Number::of('0.1')->add('0.2'); // "0.3" — strings stay exact
$n = Number::of('19.90');
$n->toString(); // "19.9" — canonical decimal string
(string) $n; // same
$n->toFloat(); // 19.9
$n->toInt(); // throws — has a fractional part; round() first
json_encode($n); // '"19.9"' — serialises as the exact string