This module defines two constants:
The default unit of a BOM row: - (each)
All valid units of a BOM row.
New in version 1.1.
Exception raised if an error occurs while converting a value from one unit to another one.
New in version 1.1.
Converts a value expressed in original_unit to new_unit
Raises : | UnitConversionError if the conversion is not possible. |
---|
Here is an example :
>>> convert_unit(1, 'm', 'mm')
1000.0
>>> convert_unit(5, 'dm', 'mm')
500.0
>>> convert_unit(5, 'dL', 'm3')
0.00050000000000000001
>>> convert_unit(5, 'dL', 'kg')
------------------------------------------------------------
Traceback (most recent call last):
File "<ipython console>", line 1, in <module>
File plmpapp/utils/units.py", line 80, in convert_unit
def convert_unit(value, original_unit, new_unit):
UnitConversionError: Inconsistent units (dL, kg)