1.0.1 • Published 9 years ago
percent-change v1.0.1
percent-change
Note: percent-change
is only supported on iojs and node v4+.
To use with an older version of node, please use percent-change@0.1
.
Installation
$ npm install --save percent-change
Tests
$ npm test
API
change(from, to, places, fmt)
Example
var change = require('percent-change')
var out = change(5, 7, true)
console.log(out)
// => '40.00%'
out = change(5, 7, false)
console.log(out)
// => 0.4
To specify the decimal places:
var out = change(5, 7, 0, true)
console.log(out)
// => '40%'
Params
- from {Number} The from number
- to {Number} The to number
- places {Number} The number of decimal places (optional, defaults to 2)
- fmt {Boolean} Should we format as a percentage? (defaults to false)
change.format(from, to, places)
Example
var change = require('percent-change')
var out = change.format(5, 7)
console.log(out)
// => '40.00%'
Params
- from {Number} The from number
- to {Number} The to number
- places {Number} The number of decimal places (optional, defaults to 2)
License
Licensed under the MIT license. For more info, see LICENSE