1.0.3 • Published 4 years ago

thousandify v1.0.3

Weekly downloads
6
License
ISC
Repository
gitlab
Last release
4 years ago

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
}
  1. thousandSeparator: <String> The separator of thousands number string

  2. decimalSeparator: <String> The decimal separator

  3. 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
1.0.3

4 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago