# approximate-number

> Converts numbers into a more human-friendly format, similar to `ls`'s `--human-readable` flag (`ls -lh`) or Stack Overflow's reputation numbers. For example, 123456 becomes '123k'.

Latest version **3.0.1** (published 2026-03-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install approximate-number
pnpm add approximate-number
yarn add approximate-number
bun add approximate-number
```

## Health

**Score 68/100 (B)** — status: stable.

Positive: has types package; esm support; no vulnerabilities; has provenance; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 3.0.1 |
| Published | 2026-03-21 |
| First published | 2014-11-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/approximate-number) |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 8.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 39 |
| Author | Nathan Friedly |
| Maintainers | nfriedly |
| Keywords | approximate-number, abbreviate, abbreviated, human, friendly, readable, large, big, number, numbers, stack overflow, stack exchange, -h, format, formatter, approximate, approximation, short, simple, near, nearest, closest, round, thousand, million, billion, trillion |

## Links

- npm: https://www.npmjs.com/package/approximate-number
- Repository: https://github.com/nfriedly/approximate-number
- Issues: https://github.com/nfriedly/approximate-number/issues
- npm.io page: https://npm.io/package/approximate-number

## Alternatives

- [random-seedable](https://npm.io/package/random-seedable.md) — 27.9K weekly downloads
- [n2words](https://npm.io/package/n2words.md) — 22.2K weekly downloads
- [@stdlib/math-base-special-factorialln](https://npm.io/package/@stdlib/math-base-special-factorialln.md) — 5.7K weekly downloads
- [@stdlib/math-base-special-abs2](https://npm.io/package/@stdlib/math-base-special-abs2.md) — 1.7K weekly downloads
- [commons-math-interpolation](https://npm.io/package/commons-math-interpolation.md) — 1.4K weekly downloads

## Recent versions

- 3.0.1 (latest) — 2026-03-21
- 3.0.0 — 2026-03-20
- 2.1.1 — 2023-07-26
- 2.1.0 — 2021-05-21
- 2.0.0 — 2016-12-14
- 1.1.2 — 2014-12-15
- 1.1.1 — 2014-11-14
- 1.1.0 — 2014-11-06
- 1.0.4 — 2014-11-06
- 1.0.3 — 2014-11-06
- 1.0.2 — 2014-11-06
- 1.0.1 — 2014-11-06
- 1.0.0 — 2014-11-06

## README

# Approximate Number

[![CI](https://github.com/nfriedly/approximate-number/actions/workflows/ci.yml/badge.svg)](https://github.com/nfriedly/approximate-number/actions/workflows/ci.yml)
[![npm version](https://badge.fury.io/js/approximate-number.svg)](https://www.npmjs.com/package/approximate-number)
[![npm downloads](https://img.shields.io/npm/dm/approximate-number)](https://www.npmjs.com/package/approximate-number)

Abbreviates numbers into a more human-friendly format, similar to `ls`'s `--human-readable` flag (`ls -lh`) or Stack
Overflow's reputation numbers. For example, 123456 becomes '123k'.

Works in Node.js and in browsers.

```js
import { approximateNumber as approx } from 'approximate-number';
// to require() rather than import, use version 2.x

console.log(approx(1234));
//> 1.2k

console.log(approx(12345));
//> 12k

console.log(approx(1234, {decimal: false}));
//> 1k

console.log(approx(1234, {decimal: ','}));
//> 1,2k

console.log('My Stack Overflow reputation is %s.', approx(3671, {
  min10k: true
}));
//> My Stack Overflow reputation is 3,671.

console.log('The US national debt is %s.', approx(19939034457936, {
  prefix: '$', 
  capital: true, 
  round: true
}));
// > The US national debt is $20T.

// Truncates/floors numbers by default
approx(9999);
// > '9.9k'

// Set `round: true` to round instead of floor.
approx(9999,{round: true});
// > '10k'

```

## Getting Started

### Node.js

Install node module with: `npm install --save approximate-number`

```js
import approximateNumber from 'approximate-number';
approximateNumber(123456); // 123k
```

For CommonJS projects, use version 2.x: run `npm install --save approximate-number@2` to install and then do `const approximateNumber = require("approximate-number");` to load the module.

### Browser usage without a package manager

Grab the latest [approximate-number.js](https://github.com/nfriedly/approximate-number/blob/master/lib/approximate-number.js) and copy it onto your site.

## Options

* **separator** {String|Boolean} Default = `','`. Thousands separator - set to a string (e.g. '.') to use that string or false to not use any separator.
* **decimal** {String|Boolean} Default = `'.'`. Decimal - set to a string (e.g. ',') to use that or set to false to avoid outputting values with a decimal.
* **round** {Boolean} Default = `false`. Round numbers off rather than flooring/truncating. When true, 105000 would become '11m', when false it becomes '10m'.
* **min10k** {Boolean} Default = `false`. Do not abbreviate numbers below 10000. E.g. 9999 would become '9,999' rather than '9k'. (Stack Overflow-style).
* **prefix** {String} Default = `''`. Optional string to prepend to the value, e.g. '$'.
* **suffix** {String} Default = `''`. Optional string to append to the value, e.g. '%'.
* **capital** {Boolean} Default = `false`. Set to true to use capital letters, e.g. 3.9M instead of 3.9m
* **precision** {Number} Default = undefined. Number of significant digits. Must be greater than 0. Use of this option forces rounding.

## V3 Changes
* Converted library from CommonJS to ESM

## V2.1 Changes
* Added precision

## V2 Changes

* Added optional configuration object
* Changed default from rounding to truncation. Override with `options.round=true`.
* Started abbreviating numbers between 1000 and 9999 by default. Override with `options.min10k=true`.
* Added trillions support.
* Dropped cli support.

## License

Copyright (c) 2014-2026 Nathan Friedly  
Licensed under the MIT license.


[tests]: https://github.com/nfriedly/approximate-number/blob/master/test/approximate-number_test.js

---
_Source: https://npm.io/package/approximate-number · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
