Skip to content

Commit

Permalink
Fix decimal converter to avoid scientific notations (#826)
Browse files Browse the repository at this point in the history
xs:decimals don't support scientific notations at all.

fixes #817
  • Loading branch information
tefra authored Jul 16, 2023
1 parent d39e9aa commit cf0cf44
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ exclude: tests/fixtures

repos:
- repo: https://github.com/asottile/pyupgrade
rev: v3.7.0
rev: v3.9.0
hooks:
- id: pyupgrade
args: [ --py37-plus ]
Expand All @@ -11,11 +11,11 @@ repos:
hooks:
- id: reorder-python-imports
- repo: https://github.com/ambv/black
rev: 23.3.0
rev: 23.7.0
hooks:
- id: black
- repo: https://github.com/PyCQA/autoflake
rev: v2.1.1
rev: v2.2.0
hooks:
- id: autoflake
- repo: https://github.com/PyCQA/flake8
Expand All @@ -41,7 +41,7 @@ repos:
- id: docformatter
args: [ "--in-place", "--pre-summary-newline" ]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.4.0
rev: v1.4.1
hooks:
- id: mypy
files: ^(xsdata/)
Expand Down
6 changes: 4 additions & 2 deletions tests/formats/test_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_serialize(self):
self.assertEqual("1.5", converter.serialize(1.5))
self.assertEqual("true", converter.serialize(True))
self.assertEqual("optional", converter.serialize(UseType.OPTIONAL))
self.assertEqual("8.77683E-8", converter.serialize(Decimal("8.77683E-8")))
self.assertEqual("0.0000000877683", converter.serialize(Decimal("8.77683E-8")))
self.assertEqual("8.77683E-08", converter.serialize(float("8.77683E-8")))

def test_test(self):
Expand Down Expand Up @@ -254,7 +254,9 @@ def test_serialize(self):
self.assertEqual("INF", self.converter.serialize(Decimal("inf")))
self.assertEqual("INF", self.converter.serialize(Decimal("+inf")))
self.assertEqual("-INF", self.converter.serialize(Decimal("-inf")))
self.assertEqual("8.77683E-8", self.converter.serialize(Decimal("8.77683E-8")))
self.assertEqual(
"0.0000000877683", self.converter.serialize(Decimal("8.77683E-8"))
)


class DateTimeConverterTests(TestCase):
Expand Down
2 changes: 1 addition & 1 deletion xsdata/formats/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ def serialize(self, value: Decimal, **kwargs: Any) -> str:
if value.is_infinite():
return str(value).replace("Infinity", "INF")

return str(value)
return f"{value:f}"


class QNameConverter(Converter):
Expand Down

0 comments on commit cf0cf44

Please sign in to comment.