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

smart-decimal-format

v1.0.6

Published

Formats numbers to given decimal places and automatically switches to scientific notation when values are too small to display meaningfully.

Readme

smart-decimal-format

npm version License: ISC

A smart number formatting utility that automatically formats numbers to a specified number of decimal places and intelligently switches to scientific notation when values are too small to display meaningfully.

Features

Smart Formatting: Automatically formats numbers with precision
🔬 Scientific Notation: Converts very small numbers to scientific notation
📊 Handles Edge Cases: Properly handles zero, negative numbers, and scientific input
🎯 Type-Safe: Written in TypeScript with full type definitions
Lightweight: Zero dependencies

Installation

npm install smart-decimal-format

or using yarn:

yarn add smart-decimal-format

Usage

Basic Example

import { formatNumberToScientific } from 'smart-decimal-format';

// Format regular numbers
formatNumberToScientific(123.456789, 2);  // 123.46

// Small numbers automatically convert to scientific notation
formatNumberToScientific(0.00000012445423423, 6);  // 1.244542e-7

// Handle negative numbers
formatNumberToScientific(-0.000345, 2);  // -3.45e-4

// Zero handling
formatNumberToScientific(0, 2);  // 0.00

JavaScript (CommonJS)

const { formatNumberToScientific } = require('smart-decimal-format');

const result = formatNumberToScientific(0.00056789, 3);
console.log(result);  // 5.679e-4

API Reference

formatNumberToScientific(value, position)

Formats a number to the specified decimal places and automatically switches to scientific notation when appropriate.

Parameters

| Parameter | Type | Description | |-----------|------|-------------| | value | number | The number to format | | position | number | The number of decimal places to use |

Returns

  • Type: number
  • Description: The formatted number, either in decimal or scientific notation

Behavior

  • Zero values: Returns 0.00
  • Small positive values (0 < value < 1):
    • Converts to scientific notation if there are leading zeros matching the precision
    • Otherwise formats to specified decimal places
  • Negative values: Converts to scientific notation with specified precision
  • Large values: Formats to specified decimal places

Examples

Positive Numbers

formatNumberToScientific(123456789, 2);     // 123456789.00
formatNumberToScientific(0.012345, 4);      // 0.0123
formatNumberToScientific(10, 2);            // 10.00
formatNumberToScientific(0.234254, 1);      // 0.2

Very Small Numbers

formatNumberToScientific(0.00000012445423423, 6);  // 1.244542e-7
formatNumberToScientific(0.00056789, 3);           // 5.679e-4

Negative Numbers

formatNumberToScientific(-0.000345, 2);      // -3.45e-4
formatNumberToScientific(-123456, 3);        // -1.235e+5
formatNumberToScientific(-0.0789, 2);        // -7.89e-2
formatNumberToScientific(-98765.4321, 4);    // -9.8765e+4

Use Cases

This package is particularly useful for:

  • 📈 Scientific calculations and data visualization
  • 💰 Financial applications with varying decimal precision
  • 🔬 Laboratory data presentation
  • 📊 Dashboard and reporting tools
  • 🧮 Mathematical computations requiring smart number formatting

Development

Prerequisites

  • Node.js >= 14
  • TypeScript >= 5.0

Setup

# Clone the repository
git clone https://github.com/buddhika-senevirathna/smart-decimal-format.git

# Install dependencies
npm install

# Run tests
npm test

# Build the project
npm run build

Running Tests

npm test

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

This project is licensed under the ISC License - see the LICENSE file for details.

Author

Buddhika Senevirathna
📧 Email: [email protected]
🔗 GitHub: @buddhika-senevirathna

Issues

If you encounter any problems or have suggestions, please open an issue on GitHub.

Changelog

v1.0.1

  • Initial release
  • Smart decimal formatting
  • Automatic scientific notation conversion
  • TypeScript support
  • Comprehensive test coverage

Made with ❤️ by Buddhika Senevirathna