https://github.com/letiantian/re-percentage.js
repercentage('12%') == 0.12
https://github.com/letiantian/re-percentage.js
Last synced: 3 months ago
JSON representation
repercentage('12%') == 0.12
- Host: GitHub
- URL: https://github.com/letiantian/re-percentage.js
- Owner: letiantian
- Created: 2016-03-04T05:13:45.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-03-04T06:43:00.000Z (over 9 years ago)
- Last Synced: 2024-10-22T22:43:59.283Z (7 months ago)
- Language: JavaScript
- Size: 1.95 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# re-percentage.js
Convert string percentages to numbers.
The reverse version of [percentage.js](https://github.com/EvanHahn/percentage.js).
## Install
```
$ npm install re-percentage
```## Usage
In Node:
```js
var rp = require('re-percentage');rp('1%') // 0.01
rp('-1%') // -0.01
rp('10%') // 0.1
rp('-10%') // -0.1
rp('120%') // 1.2
rp('-120%') // -1.2
rp('12.0%') // 0.12
rp('-12.0%') // -0.12
rp('12.5%') // 0.125
rp('-12.5%') // -0.125
rp('0.23%') // 0.0023
rp('-0.23%') // -0.0023
rp('∞%') // Infinity
rp('-∞%') // -Infinityrp('1') // 0.01
rp('-1') // -0.01
rp('10') // 0.1
rp('-10') // -0.1
rp('120') // 1.2
rp('-120') // -1.2
rp('12.0') // 0.12
rp('-12.0') // -0.12
rp('12.5') // 0.125
rp('-12.5') // -0.125
rp('0.23') // 0.0023
rp('-0.23') // -0.0023
rp('∞') // Infinity
rp('-∞') // -Infinity
```In the browser:
```htmlrepercentage("89%") // 0.89
```
## License
MIT