JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 5
  • Score
    100M100P100Q36253F
  • License ISC

A function which fixes floating-point rounding errors in JavaScript

Package Exports

  • fix-floats
  • fix-floats/index.mjs

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (fix-floats) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

fix-floats

A function which fixes floating-point rounding errors in JavaScript

Importing fixFloat:

import fixFloat from "fix-floats";

Fix floating-point errors to specified number of decimal places:

const num = 0.101 + 0.202; // 0.30300000000000005

// to significant decimal places:
fixFloat(num, 3) // 0.303

// with less decimal places:
fixFloat(num, 2) // 0.3
fixFloat(num, 1) // 0.3

// with more decimal places:
fixFloat(num, 4) // 0.303
fixFloat(num, 5) // 0.303

Fix floating-point errors with predicted number of wanted decimal places:

const num = 0.101 + 0.202; // 0.30300000000000005

// decimal place prediction:
fixFloat(num) // 0.303