Skip to content

Commit

Permalink
Fix alternative number formats
Browse files Browse the repository at this point in the history
  • Loading branch information
mph- committed Oct 20, 2024
1 parent d5920e4 commit 14bd101
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
24 changes: 20 additions & 4 deletions lcapy/mnacpts.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ def __init__(self, cct, namespace, name, cpt_type, cpt_id, string,
# self.relnodes.append(node)

self._string = string
self.args = self._process_args(args)
self.args = args
args = self._process_args(args)
self.classname = self.__class__.__name__
self.keyword = keyword
self.opts = Opts(opts_string)
Expand Down Expand Up @@ -144,11 +145,26 @@ def _process_args(self, args):
suffixes = {'f': 1e-15, 'p': 1e-12, 'n': 1e-9, 'u': 1e-6,
'm': 1e-3, 'k': 1e3, 'M': 1e6, 'G': 1e9, 'T': 1e12}

def isfloat(s):
try:
float(s)
return True
except ValueError:
return False

pargs = []
for arg in args:
if (arg is not None and len(arg) > 2
and arg[-1] in suffixes and arg[0:-1].isnumeric()):
pargs.append(float(arg) * suffixes[arg[-1]])
if arg is None or len(arg) < 2:
pargs.append(arg)
continue

if arg.endswith('Meg'):
arg = arg[0:-2] + 'M'
elif arg.endswith('K'):
arg = arg[0:-1] + 'k'

if (arg[-1] in suffixes and isfloat(arg[0:-1])):
pargs.append(float(arg[0:-1]) * suffixes[arg[-1]])
else:
pargs.append(arg)

Expand Down
1 change: 0 additions & 1 deletion lcapy/schematics/components/cpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ def __init__(self, sch, namespace, name, cpt_type, cpt_id, string,

self.auxiliary_node_names = auxiliary_node_names


def _process_opts(self):

if self.sch is None:
Expand Down

0 comments on commit 14bd101

Please sign in to comment.