Next / Previous / Contents / Shipman's homepage

7.3. MixedValue.format()

To avoid the rounding problems discussed in Section 7, “class MixedValue: Handling mixed unit systems”, use a method call of this form on an instance m of the class:

m.format(decimals=0, lz=False)

The number of digits to display after the decimal point in the value of the smallest unit.


By default, the values will be displayed without left zeroes. Assert lz=True to provide left zeroes for each value.

The result returned will be a list of strings, one for each possible unit value. Examples:

>>> nearTwo = MixedValue((60,60), (1, 7, 59.995))
 >>> nearTwo.format()
['1', ' 7', '59']
 >>> nearTwo.format(decimals=4)
['1', ' 7', '59.9950']
 >>> nearTwo.format(decimals=3, lz=True)
['1', '07', '59.995']