-
Notifications
You must be signed in to change notification settings - Fork 234
Closed
Labels
Description
For users outside of the repo, calculating unit conversion between 2 units can be simplified.
Here is a code example of how users can do it now:
import { Quantity } from "@itwin/core-quantity";
const context = new SchemaContext(); // or from iModelDb.schemaContext
const provider = new SchemaUnitProvider(context);
const fromUnit = await provider.findUnitByName("Units.M");
const toUnit = await provider.findUnitByName("Units.FT");
const conversion = await provider.getConversion(fromUnit, toUnit);
const quantity = new Quantity(fromUnit, 1.0);
const converted = quantity.convertTo(toUnit, conversion);
console.log(converted?.magnitude);It involves instantiating a Quantity object and calling the convertTo method, a wrapper around an internal applyConversion method in core-quantity. We should look into
- An easy way to convert values between units without needing an instanced object (which can mean making
applyConversionnot internal) - Improving the documentation in quantity to explicitly have a code example for external developers to convert values between 2 units outside of formatting.
Reactions are currently unavailable