chopnum

Beautify long number

Usage no npm install needed!

<script type="module">
  import chopnum from 'https://cdn.skypack.dev/chopnum';
</script>

README

Chopnum

Beautify long number

API

Chopnum(num[, options])

num

Type: Number

options.step

Type: Number
Default: 3
Chunk length

options.separator

Type: String
Default:
Separate chunks with this symbol

options.round

Type: Boolean
Default: false Remove fractional part

Usage

Chopnum(12)
// => 12

Chopnum(123456789)
// => '123 456 789'

Chopnum(-123456789)
// => '-123 456 789'

Chopnum(123456789, { step: 4 })
// => '1 2345 6789'

Chopnum(123456789, { separator: '-' })
// => '123-456-789'

Changelog

v1.0.2 (2019-08-29):

  • fixed bug when minus sign was perceived as part of a number