utils/types: numeric expeanded to handle percentages
numeric() conversion function is expanded to handle percentage values in
the form "10.123%". The result is the numeric part converted to a float
and divided by 100, e.g. 0.10123.
diff --git a/devlib/utils/types.py b/devlib/utils/types.py
index be30bfc..645328d 100644
--- a/devlib/utils/types.py
+++ b/devlib/utils/types.py
@@ -68,6 +68,15 @@
"""
if isinstance(value, int):
return value
+
+ if isinstance(value, basestring):
+ value = value.strip()
+ if value.endswith('%'):
+ try:
+ return float(value.rstrip('%')) / 100
+ except ValueError:
+ raise ValueError('Not numeric: {}'.format(value))
+
try:
fvalue = float(value)
except ValueError: