float-equal

Check if two floats are almost equal

Usage no npm install needed!

<script type="module">
  import floatEqual from 'https://cdn.skypack.dev/float-equal';
</script>

README

float-equal

Check if two floats are almost equal

Due to rounding errors you shouldn't compare floats directly. Instead this module takes an upperbound for rounding errors into consideration.

Install

$ npm install float-equal

Usage

import floatEqual from 'float-equal';

console.log(0.1 + 0.2 === 0.3);
//=> false

console.log(floatEqual(0.1 + 0.2, 0.3));
//=> true