Skip to content

Commit

Permalink
Merge remote-tracking branch 'github.com/master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Tianning Li committed Oct 3, 2024
2 parents 23067b8 + f24fe9d commit 33fe701
Showing 1 changed file with 7 additions and 6 deletions.
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

0 comments on commit 33fe701

Please sign in to comment.