diff --git a/website/blog/2024-12-26-avoid-negative-division-pitfalls-in-python.md b/website/blog/2024-12-26-avoid-negative-division-pitfalls-in-python.md index 001935f..c9f1ed1 100644 --- a/website/blog/2024-12-26-avoid-negative-division-pitfalls-in-python.md +++ b/website/blog/2024-12-26-avoid-negative-division-pitfalls-in-python.md @@ -24,9 +24,7 @@ Here's the Python function where the issue occurs: ```python def int_to_float(value: int, decimal: int): - exp = 1 - for _ in range(decimal): - exp = exp * 10 + exp = 10 ** decimal return f"{value // exp:,}.{str(value % exp).zfill(decimal)}" print(int_to_float(100, 2)) # 1.00 @@ -136,9 +134,7 @@ The following is an updated version of the function that correctly handles negat ```python def int_to_float(value: int, decimal: int): - exp = 1 - for _ in range(decimal): - exp = exp * 10 + exp = 10 ** decimal if value < 0: value = -value sign = "-" diff --git a/website/docs/python/python-negative-division.md b/website/docs/python/python-negative-division.md index ebd4ff8..de87ff0 100644 --- a/website/docs/python/python-negative-division.md +++ b/website/docs/python/python-negative-division.md @@ -21,9 +21,7 @@ Here's the Python function where the issue occurs: ```python def int_to_float(value: int, decimal: int): - exp = 1 - for _ in range(decimal): - exp = exp * 10 + exp = 10 ** decimal return f"{value // exp:,}.{str(value % exp).zfill(decimal)}" print(int_to_float(100, 2)) # 1.00 @@ -133,9 +131,7 @@ The following is an updated version of the function that correctly handles negat ```python def int_to_float(value: int, decimal: int): - exp = 1 - for _ in range(decimal): - exp = exp * 10 + exp = 10 ** decimal if value < 0: value = -value sign = "-"