Reputation: 2089
We need a generic framework that will allow our application to do all kinds of conversions between the base units of the International System of Units and the derived units. It should i.e. be possible to add values with unit "meter" to values with unit "kilometer", and it should be able to determine what the unit of an expression is.
So if we calculate the product of a speed (m/s) and a time (h:mm:ss) then it should be able to determine that the resulting unit is distance (m).
Does anybody know if such a library is available somewhere, commercially or open source?
Upvotes: 1
Views: 369
Reputation: 125651
There's no way to do it directly that I've seen.
You have to convert one type into the other (or both into a common type), perform your operation, and then convert the results back.
Delphi (since 2007, at least) comes with the ConvUnit
unit that has classes that will do this type thing, and there's a sample app that demonstrates called ConvertIt
. YOu can do your own custom conversion types, which makes it pretty flexible.
There's more info in the Delphi documentation wiki.
Upvotes: 2