1
0
mirror of https://github.com/ARM-software/devlib.git synced 2025-01-31 02:00:45 +00:00

Merge pull request #162 from setrofim/numeric-pcent

utils/types: numeric expeanded to handle percentages
This commit is contained in:
marcbonnici 2017-08-17 11:17:56 +01:00 committed by GitHub
commit 210712b384

View File

@ -68,6 +68,15 @@ def numeric(value):
""" """
if isinstance(value, int): if isinstance(value, int):
return value 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: try:
fvalue = float(value) fvalue = float(value)
except ValueError: except ValueError: