X-Git-Url: https://wannabe.guru.org/gitweb/?a=blobdiff_plain;f=math_utils.py;h=62771231bb67925483bcbf714fe2a8373b591058;hb=b10d30a46e601c9ee1f843241f2d69a1f90f7a94;hp=56fb7072366ab97621e032e9aed11d13d7740b5e;hpb=97fbe845e5dfdbda22521117c1783e1fd8515952;p=python_utils.git diff --git a/math_utils.py b/math_utils.py index 56fb707..6277123 100644 --- a/math_utils.py +++ b/math_utils.py @@ -61,6 +61,22 @@ def truncate_float(n: float, decimals: int = 2): return int(n * multiplier) / multiplier +def percentage_to_multiplier(percent: float) -> float: + multiplier = percent / 100 + multiplier += 1.0 + return multiplier + + +def multiplier_to_percent(multiplier: float) -> float: + percent = multiplier + if percent > 0.0: + percent -= 1.0 + else: + percent = 1.0 - percent + percent *= 100.0 + return percent + + @functools.lru_cache(maxsize=1024, typed=True) def is_prime(n: int) -> bool: """Returns True if n is prime and False otherwise"""