What API can I use to convert quantities between different units?


#1

Need to convert a quantity in unit A to a different unit B. Unit B is convertible from unit A.


#2

There is an api on Unit.c3typ called getConversionFactor to get the conversion factor and isConvertable to check if the two units can be converted to each other


#3

But is there an API to give us the quantity in the target unit?


#4

Seems like you need a function called convert from one unit to the other exposed via the Unit.c3typ. There isn’t one already but we should add one. Please file a ticket for it.

In the meanwhile you can use the getConversionFactor to manually get the value. The above function should eliminate the 1 line of code for you