mirror of
https://github.com/ARM-software/devlib.git
synced 2025-05-13 03:24:34 +01: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:
parent
4d95656e49
commit
3d10e3eae9
@ -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