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:
commit
210712b384
@ -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:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user