1. Go to this page and download the library: Download phrity/util-numerics 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/ */
phrity / util-numerics example snippets
Phrity\Util\Numerics {
/* Methods */
public __construct(int|null $precision = null, string|null $locale = null);
public ceil(float $number, int|null $precision = null): float;
public floor(float $number, int|null $precision = null): float;
public round(float $number, int|null $precision = null): float;
public mceil(float $number, float $multipleOf): float;
public mfloor(float $number, float $multipleOf): float;
public mround(float $number, float $multipleOf): float;
public parse(int|float|string $numeric): float|null;
public format(float $number, int|null $precision = null): string;
public rand(float $min = 0, float[null $max = null, int|null $precision = null): float|null;
public precision(float $number, bool $wide = false): int;
public setLocale(string $locale): void;
}
$numerics = new Numerics(); // Default precision is 0
$numerics = new Numerics(3, 'en_US'); // Default precision is 3, default locale en-US
// Precison specified on each call
$numerics = new Numerics();
$numerics->ceil(1234.5678, 2); // 1234.57
$numerics->ceil(1234.5678, 1); // 1234.60
$numerics->ceil(1234.5678, 0); // 1235.00
$numerics->ceil(1234.5678, -1); // 1240.00
$numerics->ceil(1234.5678, -2); // 1300.00
// Precison specified as default, override is possible
$numerics = new Numerics(2);
$numerics->ceil(1234.5678); // 1234.57
$numerics->ceil(1234.5678, 0); // 1235.00
// Precison specified on each call
$numerics = new Numerics();
$numerics->floor(1234.5678, 2); // 1234.56
$numerics->floor(1234.5678, 1); // 1234.50
$numerics->floor(1234.5678, 0); // 1234.00
$numerics->floor(1234.5678, -1); // 1230.00
$numerics->floor(1234.5678, -2); // 1200.00
// Precison specified as default, override is possible
$numerics = new Numerics(2);
$numerics->floor(1234.5678); // 1234.56
$numerics->floor(1234.5678, 0); // 1234.00
// Precison specified on each call
$numerics = new Numerics();
$numerics->round(1234.5678, 2); // 1234.57
$numerics->round(1234.5678, 1); // 1234.60
$numerics->round(1234.5678, 0); // 1235.00
$numerics->round(1234.5678, -1); // 1230.00
$numerics->round(1234.5678, -2); // 1200.00
// Precison specified as default, override is possible
$numerics = new Numerics(2);
$numerics->round(1234.5678); // 1234.57
$numerics->round(1234.5678, 0); // 1235.00