Skip to content

Commit

Permalink
Lower case e in decimal representation
Browse files Browse the repository at this point in the history
  • Loading branch information
hukkin committed Jan 13, 2025
1 parent 9c77cbb commit 95b44c0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/tomli_w/_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ def format_decimal(obj: Decimal) -> str:
return "inf"
if obj == Decimal("-inf"):
return "-inf"
dec_str = str(obj)
return dec_str if "." in dec_str or "E" in dec_str else dec_str + ".0"
dec_str = str(obj).lower()
return dec_str if "." in dec_str or "e" in dec_str else dec_str + ".0"


def format_inline_table(obj: Mapping, ctx: Context) -> str:
Expand Down
6 changes: 4 additions & 2 deletions tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def test_decimal():
"decimal-nan": Decimal("nan"),
"decimal-2e3": Decimal("2e3"),
"decimal-2E3": Decimal("2E3"),
"float-2E3": float("2E3"),
}
assert (
tomli_w.dumps(obj)
Expand All @@ -23,8 +24,9 @@ def test_decimal():
decimal-inf = inf
decimal-minus-inf = -inf
decimal-nan = nan
decimal-2e3 = 2E+3
decimal-2E3 = 2E+3
decimal-2e3 = 2e+3
decimal-2E3 = 2e+3
float-2E3 = 2e+3
"""
)

Expand Down

0 comments on commit 95b44c0

Please sign in to comment.