1
0
mirror of https://github.com/ARM-software/devlib.git synced 2025-02-07 13:40:48 +00:00

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.
This commit is contained in:
Sergei Trofimov 2017-08-16 15:58:10 +01:00
parent 4d95656e49
commit 3d10e3eae9

View File

@ -68,6 +68,15 @@ def numeric(value):
"""
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: