Code Monkey home page Code Monkey logo

num-words's Introduction

num-words

An simple module to convert numbers to words for South Asian numbering system. e.g. Two crore four lakh.

Install

npm i num-words

Example

1          ->  one
12         ->  twelve
123        ->  one hundred and twenty three
1234       ->  one thousand two hundred and thirty four
12345      ->  twelve thousand three hundred and forty five
123456     ->  one lakh twenty three thousand four hundred and fifty six

Usage

const numWords = require('num-words')

const amountInWords = numWords(12345) // twelve thousand three hundred and forty five

Note: This module only supports 9 digits input. A typical usecase for such convertion is in tax invoices or charts etc. For that more than 9 digits input is not very common (and also not very readable).

Contributing

In case you notice a bug, please open an issue mentioning the input that has caused an incorrect conversion.

num-words's People

Contributors

dependabot[bot] avatar github-actions[bot] avatar salmanm avatar trangcongthanh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

num-words's Issues

Support Typescript

Would you consider supporting Typescript?

Using this in a Typescript project results in the following error:

S7016: Could not find a declaration file for module 'num-words'. '/<...>/node_modules/num-words/index.js' implicitly has an 'any' type.   Try `npm install @types/num-words` if it exists or add a new declaration (.d.ts) file containing `declare module 'num-words';`

I am not super familiar on how to do that myself, but I see many projects have type definitions under @types. The documentation for that appears to be https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html#publish-to-types. This page also has some documentation on how to build in typescript types natively to your library.

This would be a convenience when using this with a Typescript project. I currently suppress the error with:

// @ts-ignore
import numWords from 'num-words'

Support for Paise

Hi,

The package currently supports converting numbers to words in rupees, please also add support for paisa. For example if the amount is 111.47 then One Hundred Eleven and Forty Seven Paisa.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.