digitalbazaar / eslint-config-digitalbazaar

BSD 3-Clause "New" or "Revised" License
2 stars 1 forks source link

Add 'no-loss-of-precision': 'error' & tests for it. #44

Closed aljones15 closed 4 years ago

aljones15 commented 4 years ago

Addresses Issue: https://github.com/digitalbazaar/eslint-config-digitalbazaar/issues/42

no-loss-of-precision: "error"

Source: https://eslint.org/docs/rules/no-loss-of-precision

This rule would disallow the use of number literals that immediately lose precision at runtime when converted to a JS Number due to 64-bit floating-point rounding. Rule Details

In JS, Numbers are stored as double-precision floating-point numbers according to the IEEE 754 standard. Because of this, numbers can only retain accuracy up to a certain amount of digits. If the programmer enters additional digits, those digits will be lost in the conversion to the Number type and will result in unexpected behavior.