https://github.com/c0bra/text2num.js
Convert numbers written in English to numbers
https://github.com/c0bra/text2num.js
Last synced: over 1 year ago
JSON representation
Convert numbers written in English to numbers
- Host: GitHub
- URL: https://github.com/c0bra/text2num.js
- Owner: c0bra
- Created: 2012-12-27T18:16:51.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2013-01-30T15:52:54.000Z (over 13 years ago)
- Last Synced: 2025-03-15T22:09:13.887Z (over 1 year ago)
- Language: CoffeeScript
- Size: 125 KB
- Stars: 0
- Watchers: 3
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# text2num.js
Convert English phrases to their numerical equivalent. Code translated from and embellished on: [https://github.com/ghewgill/text2num](https://github.com/ghewgill/text2num)
[](https://travis-ci.org/c0bra/text2num.js)
## Installation
```
npm install text2num
```
## Usage
```
require('text2num')
# Simple
number = text2num("three")
# number == 3
# Longer
text2num("sixty thousand five hundred two")
# 60502
# Use hyphens if you like
text2num("six-hundred three")
# 603
# And the word "and"
text2num("six-hundred and three")
# 603
# Use decimals
text2num("fifty point two")
# 50.2
text2num("fifty dot two")
# 50.2
# Longer decimals
text2num("fifty point two hundred one")
# 50.201
text2num("fifty point two thousand and fifty two")
# 50.2052
```
## Additions welcome!
Just send a pull request