npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@peter-present/format-number

v0.0.12

Published

A lightweight, zero-dependency JavaScript/TypeScript library for precise number formatting. Designed for financial applications, crypto dashboards, and scientific data where precision is paramount.

Readme

format-number

A lightweight, zero-dependency JavaScript/TypeScript library for precise number formatting. Designed for financial applications, crypto dashboards, and scientific data where precision is paramount.

Unlike standard libraries that rely on floating-point math, format-number uses internal string-based arithmetic to handle numbers of any size (including string, number, and bigint) without losing a single decimal point.

For detailed documentation, visit: here

Key Features

  • Zero Precision Loss: Uses string manipulation for rounding and formatting to avoid binary floating-point errors.
  • Robust Input Parsing: Centralized parsing handles messy strings with currency symbols ($€£¥), commas, underscores, and scientific notation.
  • Advanced Rounding: 5 strategies (half, up, down, banker, truncate) with customizable decimal precision.
  • Intelligent Notation: Format small numbers with subscript zeros (e.g., 0.0₃5) or standard scientific notation.
  • Flexible Compacting: Shorten massive numbers into readable strings like 1.5T or 20.4B.
  • Fluent Chainable API: Build complex formatting logic with a clean, readable syntax.

Robust Parsing & Error Handling

The library follows a Single-Gate Parsing philosophy. High-level entry points (FN, formatNumber, and parseNum) are designed to be robust and will attempt to clean and normalize nearly any "number-like" string.

[!IMPORTANT] Internal functions (like round, compact, scientific, etc.) are optimized for performance and assume valid numeric strings. Passing completely invalid non-numeric data (e.g., "abc") directly to these utilities may result in fallback values or undefined behavior.

For manual parsing with custom error handling, use parseNum:

import { parseNum } from '@peter-present/format-number';

// Default fallback is '--'
parseNum('invalid'); // '--'

// Custom fallback for your own error boundaries
parseNum('not-a-number', { fallback: 'NaN' }); // 'NaN'
parseNum('null', { fallback: '0' }); // '0'

Installation

# npm
npm install @peter-present/format-number

# yarn
yarn add @peter-present/format-number

# bun
bun install @peter-present/format-number

Core API

formatNumber(value, options)

The primary entry point for one-off formatting. It combines parsing, rounding, and visualization.

import { formatNumber } from '@peter-present/format-number';

// Currency & Rounding
formatNumber('$1,234.567', { prefix: '€', precision: 2 }); // '€1234.57'

// Compact Notation
formatNumber(1500000000, { isCompact: true }); // '1.5B'

// Special Notations
formatNumber(0.00005, { notation: 'subscript' }); // '0.0₄5'
formatNumber(12345, { notation: 'scientific' }); // '1.2345e+4'

FN(value) - Fluent API

Best for complex, multi-step formatting requirements where readability is key.

import { FN } from '@peter-present/format-number';

const formatted = FN('1234567.89')
  .round({ precision: 0, rounding: 'banker' })
  .prefix('Balance: ')
  .suffix(' USD')
  .toNumber();

console.log(formatted); // 'Balance: 1234568 USD'

// Seamlessly combine with compact and notation
FN(1500).compact({ precision: 1 }).prefix('$').toNumber(); // '$1.5K'

round(value, options)

Independent rounding utility with high-precision string logic.

import { round } from '@peter-present/format-number';

round(1.235, { precision: 2, rounding: 'half' }); // '1.24'
round(1.235, { precision: 2, rounding: 'down' }); // '1.23'

Configuration Reference

RoundingMode

| Mode | Description | | :--------- | :--------------------------------------------------------------------- | | half | Rounds to the nearest neighbor (rounds away from zero if equidistant). | | up | Rounds towards Positive Infinity. | | down | Rounds towards Negative Infinity. | | truncate | Rounds towards Zero (trims decimals). | | banker | Rounds to the nearest even neighbor (minimizes statistical bias). |

FormattingConfigType

| Property | Type | Default | Description | | :---------- | :---------------------------- | :---------- | :------------------------------------------------- | | precision | number | 0 | Number of decimal places to maintain. | | rounding | RoundingMode | 'half' | Strategy used for rounding. | | prefix | string | "" | Text prepended to the result. | | suffix | string | "" | Text appended to the result. | | isCompact | boolean | false | Whether to use K/M/B/T suffixes for large numbers. | | notation | 'subscript' \| 'scientific' | undefined | Special formatting for extreme values. |

License

ISC