Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

float-equal

sindresorhus1.2kMIT3.0.0TypeScript support: definitely-typed

Check if two floats are almost equal

float, number, epsilon, equal, same, almost, compare, comparison, round, near, tolerance, upperbound

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