https://github.com/fantasyui-com/calculate-percent
Tiny easy to find percentage calculator that returns a fraction of 1, with customizable precision. [Algorithm, Math]
https://github.com/fantasyui-com/calculate-percent
Last synced: 12 months ago
JSON representation
Tiny easy to find percentage calculator that returns a fraction of 1, with customizable precision. [Algorithm, Math]
- Host: GitHub
- URL: https://github.com/fantasyui-com/calculate-percent
- Owner: fantasyui-com
- License: gpl-3.0
- Created: 2018-06-13T16:32:11.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2021-07-14T02:54:05.000Z (almost 5 years ago)
- Last Synced: 2025-02-10T20:18:20.416Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 20.5 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# calculate-percent
Tiny easy to find percentage calculator that returns a simple integer [Algorithm, Math]
```JavaScript
const calculatePercentSimple = require('calculate-percent/simple.js');
const val = 50;
const max = 100;
console.log( calculatePercentSimple(val, max) ); // -> 50
```
Please note that min is optional and zero by default
```JavaScript
const calculatePercent = require('calculate-percent');
const val = 0;
const min = -100;
const max = 100;
console.log( calculatePercent(val, max, min) ); // -> 50
```
## Breaking API Changes in 2.x
I felt that returning a fraction, and asking for precision was making things too difficult.
I think it is best to simply pct(250, 1000) and be done with it. In the rare case that one is not working with zero we add the min: pct(250,1000,-1000).