Open lpatiny opened 5 years ago
Internally we try to store the values in SI but sometimes we need in a code executor the value in the unit specified by the user.
We should add a utility function like:
function getValue(value, options={}) { const { customUnit } = options; let unit = mathjs.unit(String(value.unit)); unit.value = Number(value.SI); let number; if (customUnit) { unit = unit.to(customUnit); number = unit.toNumber(options.unit); } else { const unitStr = String(value.unit); number = unit.toNumber(unitStr); } return number; }
@stropitek an idea where to place it ?
I think the type renderer is already using a similar logic so it should be shared in a utility library for mathjs in the visualizer
Internally we try to store the values in SI but sometimes we need in a code executor the value in the unit specified by the user.
We should add a utility function like:
@stropitek an idea where to place it ?