Babel plugin for float equal
0.1 + 0.2 === 0.3
// => false
WTF!?!?? Because there is rounding error.
Use this plugin.
0.1 + 0.2 === 0.3
// => true
In many cases, this one is more convenient. However, you should avoid using floating point numbers.
$ npm install --save-dev babel-plugin-float-equal
.babelrc
{
plugins: ["float-equal"]
}
0.1 + 0.2 === 0.3
↓ ↓ ↓ ↓ ↓ ↓
typeof (0.1 + 0.2) === 'number' && typeof 0.3 === 'number'
? Math.abs(0.1 + 0.2 - 0.3) < Number.EPSILON
: 0.1 + 0.2 === 0.3
Thanks goes to these wonderful people (emoji key):
akameco 💻 📖 |
---|
This project follows the all-contributors specification. Contributions of any kind welcome!
MIT © akameco