Giter VIP home page Giter VIP logo

millify's Introduction

Millify Build Status

Converts long numbers into pretty, human-readable strings.

Before ๐Ÿ˜’ After ๐ŸŽ‰
2000 '2K'
10000 '10k'
42500 '42.5 kg'
1250000 '1.25 MB'
2700000000 '2.7 bil'

Install

Get it on npm:

npm install millify

Usage

Command line

millify 10000
# 10K

See millify --help for options.

Programmatically

millify(number, options)

const millify = require('millify')

millify(2500)
// 2.5K

millify(1024000, {
  precision: 3,
  lowerCase: true
})
// 1.024m

millify(39500, {
  precision: 2,  
  decimalSeparator: ','
})
// 3,95K

millify(1440000, {
  units: ['B', 'KB', 'MB', 'GB'],
  space: true,
})
// 1.44 MB

Options

Name Type Default Description
precision number 2 Number of significant figures to use
decimalSeparator string '.' Desired decimal separator (e.g. decimal point or comma)
lowerCase boolean false Use lowercase abbreviations
space boolean false Add a space between number and abbreviation
units Array<string> ['', 'K', 'M', 'B', 'T', 'P', 'E'] Unit abbreviations

millify's People

Contributors

amio avatar dbankier avatar izolate avatar kikobeats avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.