Socket
Book a DemoInstallSign in
Socket

thousandify

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

thousandify

Currency thousand format

1.0.3
latest
Source
npmnpm
Version published
Weekly downloads
923
8.97%
Maintainers
1
Weekly downloads
 
Created
Source

thousandify

Currency thousand format

NPM Version NPM Downloads

Installation

$ npm install thousandify

Usage

const thousandify = require('thousandify');

// 123456 -> '123,456'
console.log(thousandify(123456))

// 123456.1 -> '123,456.1'
console.log(thousandify(123456.1))

// 123456.123 -> '123,456.123'
console.log(thousandify(123456.123))

// 123456 -> '123,456.00'
console.log(thousandify(123456, { decimalDigits: 2 }))

// 123456.1-> '123,456.10'
console.log(thousandify(123456.1, { decimalDigits: 2 }))

// 123,456.123 -> '123,456.12'
console.log(thousandify(123456.123, { decimalDigits: 2 }))

// 123456 -> '123 456'
console.log(thousandify(123456, { thousandSeparator: ' ' }))

Syntax

thousandify(currency, option)

currency

Required, <Number | BigInt | String>

option

Optional, the default value is:

{
    thousandSeparator: ',', 
    decimalSeparator: '.',
    decimalDigits: false
}
  • thousandSeparator: <String> The separator of thousands number string

  • decimalSeparator: <String> The decimal separator

  • decimalDigits: <Number | Falsy>

  • Falsy: Do not handle the dicimal

    // 123456 -> '123,456'
    console.log(thousandify(123456))
    
    // 123456.1 -> '123,456.1'
    console.log(thousandify(123456.1))
    
    // 123456.123 -> '123,456.123'
    console.log(thousandify(123456.123))
    
  • Number: The count of decimal

    // 123456 -> '123,456.00'
    console.log(thousandify(123456, { decimalDigits: 2 }))
    
    // 123456.1-> '123,456.10'
    console.log(thousandify(123456.1, { decimalDigits: 2 }))
    
    // 123,456.123 -> '123,456.12'
    console.log(thousandify(123456.123, { decimalDigits: 2 }))
    
    // 123,456.123 -> '123,456'
    console.log(thousandify(123456.123, { decimalDigits: 0 }))
    

Run UT

To run the test suite, first install the dependencies, then run npm test:

$ npm install
$ npm test

Keywords

format

FAQs

Package last updated on 14 Oct 2021

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.