Skip to content

Commit

Permalink
fix: use power operator
Browse files Browse the repository at this point in the history
  • Loading branch information
Oreoxmt committed Dec 26, 2024
1 parent 1e96908 commit e932115
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = "-"
Expand Down
8 changes: 2 additions & 6 deletions website/docs/python/python-negative-division.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = "-"
Expand Down

0 comments on commit e932115

Please sign in to comment.