Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added cleanup for number_convert to address errors #122

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions finvizfinance/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,17 @@ def image_scrap_function(url, chart, timeframe, urlonly):


def number_covert(num):
"""covert number(str) to number(float)
"""Convert number(str) to number(float)

Args:
num(str): number of string
num(str): number as a string
Return:
num(float): number of string
num(float or None): number converted to float or None
"""
if num == "-":
if not num or num == "-": # Check if the string is empty or is "-"
return None
elif num[-1] == "%":
num = num.strip() # Remove any surrounding whitespace
if num[-1] == "%":
return float(num[:-1]) / 100
elif num[-1] == "B":
return float(num[:-1]) * 1000000000
Expand All @@ -154,7 +155,7 @@ def number_covert(num):
elif num[-1] == "K":
return float(num[:-1]) * 1000
else:
return float("".join(num.split(",")))
return float(num.replace(",", "")) # Remove commas and convert to float


def format_datetime(date_str):
Expand Down