Next / Previous / Contents / Shipman's homepage

27.8. FoDim.convert(): Convert to different units

This function uses the static method Section 27.9, “FoDim.confactor(): Find a conversion factor” to find the number that must be multiplied by the current .n value to express it in the new units.

fosox.py
# - - -   F o D i m . c o n v e r t

    def convert(self, newUnits):
        '''Convert to the same value in different units (appproximately).
        '''
        #-- 1 --
        # [ factor   :=  the number by which self.n must be multiplied
        #       to convert from self.units to newUnits ]
        factor = FoDim.confactor(self.units, newUnits)

        #-- 2 --
        return FoDim(self.n * factor, newUnits)