simplifyNodeUnit

API / publicodes / simplifyNodeUnit

function simplifyNodeUnit<Node>(node): Node

Simplify if possible the unit of a node

If not used, the result of the evaluation of a node will have the most precise unit possible, in order to prevent rounding errors.

Type Parameters

Type ParameterDefault type
Node extends EvaluatedNodeEvaluatedNode

Parameters

ParameterTypeDescription
nodeNodeThe node to simplify

Returns

Node

The node its unit simplified

Example

simplifyNodeUnit(engine.evaluate('42 €/mois * 1 an'))
// returns { nodeValue: 504, unit: { numerators: ['€'], denominators: [] } }

Defined in

packages/core/src/nodeUnits.ts:20