Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

currency-in-words

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

currency-in-words

A light-weight, fast and efficient lib that converts currency or any numbers to corresponding words

  • 2.2.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5
decreased by-93.42%
Maintainers
1
Weekly downloads
 
Created
Source

currency-in-words

Convert currency or similar number formats to respective words

Installation:



npm i currency-in-words

Usage:


import { convert } from 'currency-in-words'

/*
* format: 'intl' | 'in'
* lang: 'en'
*
* convert: (string, { format: string, lang: string }) => string
*/

//  indian-system
const result = convert('777')

//  international-system
const result = convert('777', { format: 'intl' }) seven
console.log('777')  // seven hundred seventy seven
console.log('1022') // one thousand twenty two
console.log('1,022') // NaN
console.log('66.123') // sixty six.twelve
console.log('99.11') // ninety nine.eleven
console.log('99.09') // ninety nine; decimals lesser than .10 is rejected

console.log('100000') // one lakh
console.log('100000', { format: 'int' }) // one hundred thousand

Note

  1. Expect NaN when ',' is present, eg: '100,000.99'
  2. Expect NaN when any invalid characters are present, eg: 10E55
  3. Fractional part is corrected to two places
  4. Decimals from .00 to .09 is ignored.
  5. However, visit Hacks to learn how to handle these limitations

Compatibility


Supports upto 15 digits for both indian and international systems on their integer part. A RangeError will be thrown for length beyond 15.

eg: calling convert with 100,000,000,000,000 * 10 will throw a range error

International system:

999,999,999,999,999 (1 quadrillion - 1)

Indian system:

99,99,99,99,99,99,999 (100 crore crore - 1)

Hacks



Hard time passing it as a string? cast it from the source
const amount = 0.99
const result = convert(`${amount}`) //  zero.ninety nine

Eliminate commas
const amount = '1,000.99'
const sanitized = amount.replace(/,/, '') //  1000.99

Want decimal places not to be corrected? Control it from code.
const amount = '123.123'
const [dollars, cents] = amount.split('.')
const result = `${convert(dollars)}.${convert(cents)}` // one hundred twenty threee.one hundred twenty three

Keywords

FAQs

Package last updated on 15 Apr 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc