drminnaar / react-calculator-standard

A calculator that provides the essential arithmetic operations, an expression builder, and a complete history of all expressions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

If the input is 23.8 - 7.1, the result would be incorrrect.

ChrisWongAtCUHK opened this issue · comments

The result is 16.700000000000003.

This could be solved by configuring the use of BigNumbers instead of numbers by default in mathjs(in constructor of CalculatorEngine.js):

math.config({
    number: 'BigNumber', // Default type of number:
    // 'number' (default), 'BigNumber', or 'Fraction'
    precision: 64        // Number of significant digits for BigNumbers
});

https://mathjs.org/docs/datatypes/bignumbers.html

The variable result should be parsed

result = math.eval(expression).toNumber();

https://mikemcl.github.io/decimal.js/#toNumber