Files
bet/common/bet_tools.py
2025-10-25 15:44:51 +08:00

22 lines
579 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

def american_odds_to_probability(odds: int) -> float:
"""
根据美式赔率计算概率(以小数形式返回)
:param odds: 美式赔率(正数或负数)
:return: 概率0~1之间的小数
"""
if odds > 0:
probability = 100 / (odds + 100)
else:
probability = abs(odds) / (abs(odds) + 100)
return probability
# 示例
if __name__ == "__main__":
odds_list = [+150, -200, +300, -120]
for odds in odds_list:
prob = american_odds_to_probability(odds)
print(f"赔率 {odds}: 概率 {prob:.4f}")