1.1.3 • Published 6 months ago

prettydigits v1.1.3

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

PrettyDigits

Changes long 'ugly' numbers into short pretty and readable strings 🌸

Install with NPM

npm i prettydigits
BeforeCommandAfter
1000prettyDigits(1000)'1 K'
10000prettyDigits(10000)'10 K'
1000000prettyDigits(1000000)'1 M'
0.0004356prettyDigits(0.0004356)'0.0004'
100prettyDigits(100,{units:['b']})'100 b'
-1250prettyDigits(-1250,{precision: 2})'-1.25 K'

Useage

  import {prettyDigits} from 'prettyDigits'
  //or
  const {prettyDigits} = require('prettyDigits');

  prettyDigits(3500); // '4 K'

  prettyDigits(1293943, {precision: 3, tolowercase: true}) // '1.294 m'

  prettyDigits(-12345, {space: false, units: ['b','kb','mb','gb','tb']}) // '-12kb'

  prettyDigits(0.005431351234, {precision: 2}) // '0.00543'

  prettyDigits(0.000000765) // '7.65e-7' also applies for negative numbers

Numbers that are lower than 1e-7 get a scientific notion string returned.

Options

NameTypeDefault ValuesDescription
precisionnumber0Number of decimal places to use. If the number is between 1 and 0 the precision starts at where the trailing zeros end. Eg prettyDigits(0.0053,{precision: 0}) = '0.005'
tolowercasebooleanfalseChange abbreviation to lower case
spacebooleantrueAdds a space between abbreviation and number
unitsArray["","K","M","B","T"]Change the units to your own custom ones
1.1.3

6 months ago

1.1.2

6 months ago

1.1.1

6 months ago

1.1.0

6 months ago

1.0.5

6 months ago

1.0.4

6 months ago

1.0.3

6 months ago

1.0.2

6 months ago

1.0.1

6 months ago

1.0.0

6 months ago