this library is based on bigint
type so it's precision has virtually the same limitations as bigint
limitations
if you need to perform a precise calculation just use this library, and it looks like this:
import RationalNumber from 'ratnum'
console.log(Number(new RationalNumber(0.1).add(0.2)))
/// 0.3
view the test files for more usage examples
unfortunately JavaScript has poor support of operator overloading so you'll be forced to use those ugly methods like .add
, .substract
, etc., but simple overloads like .toString
(String(...)
), valueOf
(Number(...)
) and toJSON
(JSON.stringify(...)
) are supported
pull-requests and suggestions are welcomed