Skip to content

Commit

Permalink
Mouser API - Strip extra dots in price
Browse files Browse the repository at this point in the history
  • Loading branch information
usbalbin committed Jan 6, 2025
1 parent cac6e5c commit 46ec914
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions kicost/distributors/api_mouser.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ def get_number(string):
if index is None:
raise MouserError('Malformed price: ' + string)
string = string.replace(',', '.')
dot_count = string.count('.')
if dot_count > 1:
string = string.replace('.', '', dot_count - 1)
end = next((i for i, d in enumerate(string[index:], start=index) if not (d.isdigit() or d == '.')), None)
if end is not None:
return float(string[index:end])
Expand Down

0 comments on commit 46ec914

Please sign in to comment.