Replies: 4 comments
-
The |
Beta Was this translation helpful? Give feedback.
-
I see. In our case we were a bit surprised that math.eval('2 + 2')
>> Object { constructor: Decimal(), s: 1, e: 0, d: Array[1] }
math.eval('F1 / F2', { F1: 5.0, F2: 10.0 })
>> 0.5 One problem we want to solve is weird js math issues: math.eval('F1 * F2', { F1: 0.575, F2: 124.5 })
>> 71.58749999999999
math.eval('F1 * F2', { F1: math.bignumber(0.575), F2: math.bignumber(124.5) }).toNumber()
71.5875 We'd also like to take advantage of the niceties of bignumber after the fact, like convenient rounding and decimal places. Instead of having to wrap all of our numbers on the way in, it would be great if there were a setting to just always wrap inputs in bignumber. Odds are, if we're using |
Beta Was this translation helpful? Give feedback.
-
The What you could do is create a a util function to turn all input into BigNumbers: math.confg({number: 'BigNumber'});
function myEval (expr, scope) {
// convert numbers in the scope into BigNumbers
var _scope = {};
for (var prop in scope) {
var value = scope[prop];
_scope[prop] = (typeof value === 'number') ? math.bignumber(value) : value;
}
// evaluate
return math.eval(expr, _scope);
} |
Beta Was this translation helpful? Give feedback.
-
Yeah, we were thinking of doing something like that. Just seemed like it might be nice to have a _scope[prop] = math.bignumber(scope[prop]) Since bignumber handles other types as well. |
Beta Was this translation helpful? Give feedback.
-
We came across the docs for bignumber and were excited to see the
bignumber
config. Once we played around with it for a while, we were surprised to find it was still using just normal numbers when evaluating formulas. It would be great if there was an option to always cast input values to bignumbers so that we don't have to remember to do it everywhere we calculate a formula.Beta Was this translation helpful? Give feedback.
All reactions