# nstr

> JavaScript utility to stringify numbers without floating-point UI artifacts

nstr is a lightweight JavaScript library and web demo created by Shu Ding that formats numbers into clean strings. It automatically detects floating-point calculation anomalies, such as repetitive 9s or 0s caused by binary arithmetic, and cleans them up without requiring hardcoded decimal rounding across an entire UI.

Website: https://nstr.vercel.app/

## What it is for

- Format dynamically calculated numbers in frontend UIs without seeing values like 0.30000000000000004
- Display pricing or currency calculations cleanly without manually tweaking toFixed calls
- Test floating-point string conversions interactively in the browser before coding

## Features

- Automatic detection of consecutive repeating 0s and 9s generated by floating-point math
- Avoids fixed decimal formatting issues where small numbers become zero
- Configurable maxDecimals parameter to cap maximum digits (defaults to 10)
- Configurable threshold parameter to tune pattern detection sensitivity
- Interactive web playground to compare nstr against native toString, toFixed, and toPrecision

## Pricing

Free

## Details

- Type: Web app
- Category: [Development](https://xiry.app/topics/development.md)
- Open source: yes
- Platforms: Web, Code library
- For: Frontend and JavaScript developers formatting numeric outputs for user interfaces
- Tags: javascript, numbers, math, frontend, utility, open source

## Why it was saved

- [@shuding, 22 August 2025](https://x.com/shuding/status/1958854412274934222): Fixes the classic problem of displaying something like $1989.9999999999998 instead of $1990 when rendering computed numbers in a UI.

## Related

- [Motion](https://xiry.app/resources/motion): Open-source animation library for React, Vue, and vanilla JavaScript (Website, Freemium)
- [Anime.js](https://xiry.app/resources/anime-js): Lightweight, modular JavaScript animation engine for CSS, SVG, and DOM elements (Website, Open source)
- [coss ui](https://xiry.app/resources/coss-ui): Modern UI component library built on top of Base UI (Web app, Free)
- [GSAP](https://xiry.app/resources/gsap): High-performance JavaScript animation library for web elements, SVG, and canvas. (Website, Freemium)
- [2023 JavaScript Rising Stars](https://xiry.app/resources/2023-javascript-rising-stars): Annual overview of the fastest-growing JavaScript GitHub repositories in 2023. (Website, Free)
- [COBE](https://xiry.app/resources/cobe): Lightweight 5KB WebGL globe with CSS anchor positioning support (Web app, Open source)

Updated 10 October 2026. Page: https://xiry.app/resources/nstr

Make your own library: Xiry takes your saved reels, tweets, Reddit bookmarks and Watch Later videos, makes them searchable and pulls the useful stuff out, like this library. It's invite-only for now; join the waitlist at https://xiry.app/#waitlist.
