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

to-fixed-for-real

v1.0.3

Published

Fix two decimal cases in currency value without worrying about wrong math rounds.

Downloads

10

Readme

to-fixed-for-real

npm version License: MIT

A robust JavaScript utility to truncate numbers to a fixed number of decimal places—without rounding errors. Ideal for currency and financial calculations where precision and predictability are critical.


✨ Features

  • Truncates numbers to a specified number of decimal places (no rounding)
  • Handles both string and number inputs
  • Accepts commas or periods as decimal separators
  • Supports negative numbers
  • Lightweight and dependency-free
  • Fully tested with Jest

Motivation

JavaScript’s native toFixed method rounds values, which can lead to inaccuracies in financial or scientific applications. This package provides a reliable way to truncate (not round) numbers to the desired decimal places, supporting both string and number inputs, and handling commas as decimal separators.


Installation

npm install to-fixed-for-real

Usage

Basic Example

const toFixed = require('to-fixed-for-real');

console.log(toFixed(12.599, 2)); // 12.59
console.log(toFixed('982,51832', 2)); // 982.51
console.log(toFixed(10, 2)); // 10.0
console.log(toFixed(-21381923.32938989, 2)); // -21381923.32

Input/Output Table

| Input | Code Example | Output | |--------------------|-------------------------------------|---------------| | 12.599, 2 | toFixed(12.599, 2) | 12.59 | | '982,51832', 2 | toFixed('982,51832', 2) | 982.51 | | 10, 2 | toFixed(10, 2) | 10.0 | | -4.3, 2 | toFixed(-4.3, 2) | -4.3 | | 1.2345, 2 | toFixed(1.2345, 2) | 1.23 | | '10.58928', 2 | toFixed('10.58928', 2) | 10.58 | | '164252,', 2 | toFixed('164252,', 2) | 164252.0 | | 0, 2 | toFixed(0, 2) | 0 |

Edge Cases

// Handles string input with comma as decimal
console.log(toFixed('164252,', 2)); // 164252.0

// Handles string input with no decimals
console.log(toFixed('10', 2)); // 10.0

// Handles zero
console.log(toFixed(0, 2)); // 0

API

toFixed(num, floatingPoint)

| Parameter | Type | Description | |--------------- |---------------- |-----------------------------------------------------------------------------| | num | number | string | The value to truncate. Accepts numbers or strings (with . or ,). | | floatingPoint| number | The number of decimal places to keep. If omitted, all decimals are kept. |

Returns: number — The truncated value.

Behavior

  • Truncates, does not round.
  • Handles negative numbers and string inputs.
  • Converts commas to periods for decimal separation.

Testing

This project uses Jest.

npm test

Contributing

Contributions, issues, and feature requests are welcome! Please:

  • Open an issue for bugs or feature requests
  • Fork the repo and submit a pull request for improvements
  • Add tests for new features or edge cases

License

This project is licensed under the MIT License.


Author

nethanos