egonw / jqudt

Java library for working with the QUDT ontology and data using it.
Other
14 stars 8 forks source link

Adjusting calculation of unit conversion #7

Open LeebPhil opened 3 years ago

LeebPhil commented 3 years ago

Currently unit conversion is calculated by

        newMeasurement.setValue(
            ((value
            // convert to the base unit
            * unit.getMultiplier().getMultiplier() + unit.getMultiplier().getOffset())
            // convert the base unit to the new unit
            - newUnit.getMultiplier().getOffset()) / newUnit.getMultiplier().getMultiplier() 
        );

This leads to some problem, e.g. 20°C would be -300°F and not 68°F.
Calculation should be adjusted to the following way:
https://github.com/qudt/qudt-public-repo/wiki/Support-for-measures-of-absolute-values-and-for-intervals-(differences)#converting-units-on-linear-scales

LeebPhil commented 3 years ago

added conversion of absolute units in update/unit-branch of my fork