Install millify via npm
mainYou can install the millify package using npm to convert long numbers into human-readable strings.
npm install millifyrepository·main·Indexed 41 days ago
https://github.com/izolate/millifyA utility library and CLI tool that converts large numbers into human-readable, abbreviated strings (e.g., 1000 to '1k'). Version 6.1.0 supports programmatic use via the millify() function with customizable MillifyOptions for precision, locales, and unit abbreviations.
You can install the millify package using npm to convert long numbers into human-readable strings.
npm install millifyThe millify function accepts an optional MillifyOptions object to customize the output format.
| Name | Type | Default | Description |
|---|---|---|---|
precision | number | 1 | Number of decimal places to use |
locales | string | Array<string> | browser language | Formats the number in different languages |
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(39500, {
precision: 2,
locales: "de-DE"
});
// 3,95K
millify(1440000, {
units: ["B", "KB", "MB", "GB", "TB"],
space: true,
});
// 1.44 MBImport millify to convert numbers to formatted strings in your code.
ESM Import:
import millify from "millify";
CommonJS Import:
const { millify } = require("millify");
import millify from "millify";
millify(2500); // 2.5K
millify(1024000, {
precision: 3,
lowercase: true
});
// 1.024mWhen initializing Millify, you can provide a MillifyOptions object to customize how numbers are formatted.
Key configuration properties include:
precision: The number of significant figures to display (default: 1).locales: A BCP 47 language tag (e.g., `You can use millify directly from your terminal by passing a number as an argument. Use the --help flag to view available options.
$ millify 12345
12.3KThe millify function is the primary entry point for the library. It is used to format large numbers into human-readable strings (e.g., converting 1000 to 1k). You can import it using either a named import or a default import depending on your module system configuration.
import millify from 'millify';
// or
import { millify } from 'millify';
const formatted = millify(1000);
console.log(formatted); // '1k'The millify command-line tool converts long numbers into human-readable strings (e.g., converting 1000 to 1k).
Usage:
millify <number> [options]
Positional Arguments:
number: The numeric value you want to convert.Options:
--precision, -p (number, default: 1): The number of decimal places to include.--decimal, -d (string, default: .): The character used as the decimal separator.--lowercase, -l (boolean, default: false): If set, converts unit abbreviations to lowercase.--space, -s (boolean, default: false): If set, adds a space between the number and the unit.--units, -u (string): Specify custom unit abbreviations. You can provide multiple unit flags to define a sequence (e.g., -u B -u KB -u MB).# Run with default options
millify 1000
# Set precision to 2 decimal places
millify 15025 --precision 2
# Use lowercase units and add a space after the value
millify 1000 --lowercase --space
# Use a comma as the decimal separator
millify 1000 --decimal=","
# Specify custom units
millify 1000 -u B -u KB -u MB -u GB