mirror of
https://github.com/ARM-software/devlib.git
synced 2025-02-07 05:30:44 +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:
parent
4d95656e49
commit
3d10e3eae9
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user