{"id":18495056,"url":"https://github.com/cgauge/php-largest-remainder-method","last_synced_at":"2025-05-14T02:33:17.014Z","repository":{"id":55842818,"uuid":"279293747","full_name":"cgauge/php-largest-remainder-method","owner":"cgauge","description":null,"archived":false,"fork":false,"pushed_at":"2020-12-11T12:09:43.000Z","size":13,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":7,"default_branch":"1.0","last_synced_at":"2025-01-25T17:08:53.487Z","etag":null,"topics":["hacktoberfest","math","php","rounding"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cgauge.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-07-13T12:15:49.000Z","updated_at":"2020-12-11T12:09:27.000Z","dependencies_parsed_at":"2022-08-15T07:50:14.245Z","dependency_job_id":null,"html_url":"https://github.com/cgauge/php-largest-remainder-method","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cgauge%2Fphp-largest-remainder-method","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cgauge%2Fphp-largest-remainder-method/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cgauge%2Fphp-largest-remainder-method/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cgauge%2Fphp-largest-remainder-method/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cgauge","download_url":"https://codeload.github.com/cgauge/php-largest-remainder-method/tar.gz/refs/heads/1.0","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239210668,"owners_count":19600592,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hacktoberfest","math","php","rounding"],"created_at":"2024-11-06T13:23:14.741Z","updated_at":"2025-02-16T23:27:12.611Z","avatar_url":"https://github.com/cgauge.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Largest Remainder Method ➗\n\nThis library provides a simple way to calculate percentages using the Largest Remainder Method.\n[Learn more](https://en.wikipedia.org/wiki/Largest_remainder_method).\n\n## Installation\n\n```bash\ncomposer require customergauge/remainder\n```\n\n## Usage\n\n```php\nuse CustomerGauge\\Math\\Remainder\\Remainder;\n\n$remainder = new Remainder([1, 1, 1]);\n\n$remainder-\u003eround(2); // [0.34, 0.33, 0.33]\n```\n\nIn simple terms, the goal of the Largest Remainder Method is to make\nsure that when calculating the weight of each _seat_ in the data set,\nthe aggregated percentage will not be 99.99 or 100.01.\n\nThe first example above is arbitrary and end up rounding up only the\nfirst record so that `0.34 + 0.33 + 0.33 = 1`, however not always\nthe decision is arbitrary.\n\n```php\nuse CustomerGauge\\Math\\Remainder\\Remainder;\n\n$remainder = new Remainder([92, 93, 70]);\n\n$remainder-\u003eround(2); // [0.36, 0.37, 0.27]\n```\n\nAs we can see, `0.36 + 0.37 + 0.27 = 1`, however using standard\nrounding, the result would have been different. To demonstrate that,\nlet's calculate `92 + 93 + 70 = 255`. Each value takes the following\npercentage of the whole:\n\n\n| Value | Percentage   | Round | Largest Remainder Method |\n|-------|--------------|-------|--------------------------|\n| 92    | 0.3607843137 | 0.36  | 0.36 |\n| 93    | 0.3647058823 | 0.36  | 0.37 |\n| 70    | 0.2745098039 | 0.27  | 0.27 |\n\nAs we can see from the table above, standard rounding end up\nlosing one percentage point because all three numbers round\ndown. The Largest Remainder Method will scan the values that will\nbe discarded (**0.36**~~07843137~~, **0.36**~~47058823~~, \n**0.27**~~45098039~~) and prioritize the ones with the largest\ncontribution. In this case, the 2nd value will discard `47058823`,\nwhich is the largest value discarded. That makes it viable for\nround up to fill the gap.\n\nThe fact that `93` is also the largest value does not necessarily\nhave a direct connection to the option being rounded up. We can\ntry the same example again using a much smaller number. Take\n`92 + 32 + 70 = 194`.\n\n| Value | Percentage   | Round | Largest Remainder Method |\n|-------|--------------|-------|--------------------------|\n| 92    | 0.4742268041 | 0.47  | 0.47 |\n| 32    | 0.1649484536 | 0.16  | 0.17 |\n| 70    | 0.3608247422 | 0.36  | 0.36 |","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcgauge%2Fphp-largest-remainder-method","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcgauge%2Fphp-largest-remainder-method","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcgauge%2Fphp-largest-remainder-method/lists"}