Download the PHP package kschu91/largest-remainder-method without Composer

On this page you can find all versions of the php package kschu91/largest-remainder-method. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package largest-remainder-method

Build Status Code Coverage Scrutinizer Code Quality

largest remainder method algorithm

A PHP implementation of the largest remainder method algorithm. This method is the most common way to get rid of rounding issues when working with rounded percentage values.

The problem

Assume the following example:

When rounding the above percentages using PHP´s rounding functions, we get:

Which in fact sums up to 101% instead of 100%. The largest remainder method solves this issue by doing the following steps:

  1. Rounding all values down to the nearest integer value
  2. Determining the difference between the sum of the rounded values and total value
  3. Distributing the difference between the rounded values in decreasing order of their decimal parts

Installation

If you are not familiar with composer: composer basic usage

Requirements

Basic Usage

which results in:

Working with decimals aka. precision

The default precision is set to 0. But you can change this behaviour by using the setPrecision method:

which results in:

Working with complex arrays/objects

Mostly, you don´t have the numbers you want to apply this algorithm on in a simple array as in the examples above. You rather have them in objects or associative arrays. That´s why this library also supports callbacks for applying this algorithm.

You just have to supply 2 callbacks to the usort method. The first one, to fetch the relevant number from the object. And the second one to write the rounded number back to the resulting object.

Make sure to pass the first argument of the setter callback as reference, eg. as in the example below: &$item. If not, the resulting data will maintain their original numbers and are not rounded.

which results in:


All versions of largest-remainder-method with dependencies

PHP Build Version
Package Version
Requires php Version >=7.3
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package kschu91/largest-remainder-method contains the following files

Loading the files please wait ....