Skip to content

Commit

Permalink
Merge pull request #577 from usbalbin/mouser_get_number
Browse files Browse the repository at this point in the history
[Mouser][Fixed] Strip extra dots in price
  • Loading branch information
set-soft authored Jan 7, 2025
2 parents cac6e5c + 46ec914 commit 3aa3d23
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 3aa3d23

Please sign in to comment.