decimal-subtract

Workaround for JavaScript's decimal numbers subtraction problem.


Keywords
decimal, floating point, subtraction
License
ISC
Install
npm install decimal-subtract@1.5.0

Documentation

Decimal Subtract v1.5.0 Documentation

NPM Version Package License

Table of contents

Description

Workaround for JavaScript's decimal numbers subtraction problem.

Installation

For the usage in CJS or ESM run the following command:

npm i decimal-subtract

For script tag usage include the following script:

<!DOCTYPE html>
<html>
  <body>
    <script src="https://cdn.jsdelivr.net/npm/decimal-subtract@1.5.0/dist/decimal-subtract.min.js"></script>
  </body>
</html>

Usage example

ESM:

import { decimalSubtract } from 'decimal-subtract'

console.log(1 - 0.55) // 0.44999999999999996
console.log(decimalSubtract(1, 0.55)) // 0.45

Classic:

console.log(1 - 0.55) // 0.44999999999999996
console.log(window.decimalSubtract.decimalSubtract(1, 0.55)) // 0.45