https://github.com/tei187/range-based-percentage
Class designed to find percentage of a value based on start and end points (with these points being lower and upper limits).
https://github.com/tei187/range-based-percentage
calculator percentage-calculator php range
Last synced: 3 months ago
JSON representation
Class designed to find percentage of a value based on start and end points (with these points being lower and upper limits).
- Host: GitHub
- URL: https://github.com/tei187/range-based-percentage
- Owner: tei187
- Created: 2021-10-26T08:43:13.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2021-12-23T09:42:10.000Z (almost 4 years ago)
- Last Synced: 2025-04-11T04:39:32.501Z (6 months ago)
- Topics: calculator, percentage-calculator, php, range
- Language: PHP
- Homepage:
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# RangeBasedPercentage
---RangeBasedPercentage is a utility helping to calculate the percentage of a number in given range.
Examples:
- for a range of 2-6, 4 is 50%
- for a range of 20-40, 25 is 25%
- for a range of 31-152, 63 is 26.446280991736%
- and so on...## How to use?
### Standard
```php
$calculator = new tei187\RangeBasedPercentage(5, 29); // initiate object with range 5-29
echo $calculator->getPercentage(18); // get for 18, echoes "54.166666666667"
```### Method chaining
```php
$calculator = new tei187\RangeBasedPercentage; // initiate objectecho $calculator->setRange(5, 29)->getPercentage(18); // echoes "54.16667"
echo $calculator->setRange(5, 11)->setRound(2)->getPercentage(9); // echoes "66.67"
```## Requirements
- PHP >= 7.3## Author
- [tei187](mailto:bonk.piotr@gmail.com)