A simple function to convert numbers to string percentages with options.
percentage(0.12) // "12%"
percentage(1) // "100%"
percentage(-0.1) // "-10%"
percentage(1 / 3) // "33%"
percentage(0.1234) // "12%"
percentage(0.1234, 0) // "12%"
percentage(0.1234, 1) // "12.3%"
percentage(0.1234, 2) // "12.34%"
percentage(Infinity) // "∞%"
percentage(45, 50, {percSign: true}) // "90%"
percentage(100, 50, {decimal: 3,percSign: true}) // "200.000%"
$ npm i calc-percentage
var { percentage } = require('calc-percentage');
percentage(0.12) // "12%"
percentage(1) // "100%"
percentage(-0.1) // "-10%"
percentage(1 / 3) // "33%"
percentage(0.1234) // "12%"
percentage(Infinity) // "∞%"
percentage(45, 50, {percSign: true}) // "90%"
percentage(100, 50, {decimal : 3,percSign: true}) // "200.000%"
percentage(50, 100, {decimal: 1}) // "50.0"
Type: number
Value which should be calculated.
Type: number
Total that val
should be compared against.
Type: number
Default: 0
Number of decimals.
Type: string
Append a % sign.
MIT © Mohamed Ashraf Othman