
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
js-abbreviation-number
Advanced tools
npm install js-abbreviation-number
import { abbreviateNumber } from "js-abbreviation-number";
const num = abbreviateNumber(1000, 1); // expected 1.0k
const num = abbreviateNumber(12, 0); // expected 12
const num = abbreviateNumber(1100, 2); // expected 1.10k
const num = abbreviateNumber(1100, 2, {padding: false}); // expected 1.1k
const num = abbreviateNumber(1234.56, 2); // expected 1.23k
const num = abbreviateNumber(1234, 1, {symbols: ['', 'kg']}); // expected 1.2kg
const num = abbreviateNumber(1234567, 1, {symbols: ['', 'kg']}); // expected 1234.5kg
abbreviateNumber(num: number, digit?: number, options?: {symbols?: string[]; padding: boolean}): string
digit
is optional (unless you need to specify the options
object). It defaults to 1.
The options
object is optional too:
symbols
can be an array of units, defaulting to ["", "k", "M", "G", "T", "P", "E"]
.padding
determines whether to keep the exact number of digits or to drop trailing zeroes.import { unabbreviateNumber } from "js-abbreviation-number";
const num = unabbreviateNumber("-25"); // expected -25
const num = unabbreviateNumber("-1.3k"); // expected -1300
const num = unabbreviateNumber("1.123456k"); // expected 1123.456
const num = unabbreviateNumber("666kilo", ["", "kilo", "Mega"]); // expected 666000
unabbreviateNumber(num: string, symbols?: string[]): number
symbols
is optional that can be an array of units, defaulting to ["", "k", "M", "G", "T", "P", "E"]
.
Thank you for your interest in contributing! Please feel free to put up a PR for any issue or feature request.
If you think this project is helpful just give me a ⭐️ Star is enough because i don't drink coffee 😃
This project is licensed under the MIT License - see the LICENSE.md file for details
Made with ❤️ by Mohsen Madani.
FAQs
Abbreviate numbers in javascript
The npm package js-abbreviation-number receives a total of 6,925 weekly downloads. As such, js-abbreviation-number popularity was classified as popular.
We found that js-abbreviation-number demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.