PHP code example of romainnorberg / residue
1. Go to this page and download the library: Download romainnorberg/residue 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/ */
romainnorberg / residue example snippets
Residue::create(100)->divideBy(3)->split(); // -> \Generator[33.34, 33.33, 33.33]
// or
Residue::create(100)->divideBy(3)->toArray(); // -> [33.34, 33.33, 33.33]
Residue::create(100)
->divideBy(3)
->step(0.05)
->split(); // -> \Generator[33.35, 33.35, 33.30]
$r = Residue::create(7.315)
->divideBy(3)
->step(0.05);
$r->split(); // -> \Generator[2.45, 2.45, 2.40]
$r->getRemainder(); // -> 0.015
$r = Residue::create(100)
->divideBy(3)
->decimal(0);
$r->split(); // -> \Generator[34, 33, 33]
$r->getRemainder(); // 0
//
$r = Residue::create(101)
->divideBy(3)
->decimal(0);
$r->split(); // -> \Generator[34, 34, 33]
$r->getRemainder(); // 0
$r = Residue::create(100)
->divideBy(3)
->decimal(0);
$r->split(Residue::SPLIT_MODE_EQUITY); // -> \Generator[33, 33, 33]
$r->getRemainder(); // 1
//
$r = Residue::create(101)
->divideBy(3)
->decimal(0);
$r->split(Residue::SPLIT_MODE_EQUITY); // -> \Generator[33, 33, 33]
$r->getRemainder(); // 2
$r = Residue::create(100)->divideBy(3);
foreach ($r->split() as $part) {
var_dump($part);
}
float(33.34)
float(33.33)
float(33.33)
$r = Residue::create(100)->divideBy(3);
var_dump($r->toArray());
array(3) {
[0]=>
float(33.34)
[1]=>
float(33.33)
[2]=>
float(33.33)
}