calculate-percent

2.1.0 • Public • Published

calculate-percent

Tiny easy to find percentage calculator that returns a simple integer [Algorithm, Math]

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

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).

Readme

Keywords

none

Package Sidebar

Install

npm i calculate-percent

Weekly Downloads

0

Version

2.1.0

License

ISC

Unpacked Size

34.9 kB

Total Files

6

Last publish

Collaborators

  • fantasyui.com