DEV Community

Cover image for nstr: Fix Floating-Point Precision in JavaScript
jQueryScript
jQueryScript

Posted on

nstr: Fix Floating-Point Precision in JavaScript

nstr, a JavaScript utility that automatically fixes floating-point precision artifacts in number displays.

Instead of showing users ugly decimals like 0.30000000000000004, it intelligently detects these artifacts and outputs clean strings like "0.3".

Key features:

  • Automatic precision detection without manual configuration
  • Intelligent pattern recognition for floating-point errors
  • Preserves legitimate precision while cleaning artifacts
  • Zero dependencies with TypeScript support
  • Perfect for UI components, price displays, and CSS transforms

It's useful for financial calculations and draggable components where precision errors create visual glitches.

👉 Blog Post

👉 GitHub Repo

👉 Live Demo

Top comments (0)