Skip to content

Commit

Permalink
Fix conversion of floats (#90)
Browse files Browse the repository at this point in the history
* Fix conversion of floats

Just converting the value to int will truncate, when float conversion
may have rounded already.

* Update CI Python versions
  • Loading branch information
madig authored Jul 30, 2024
1 parent 2d4c06c commit cff786e
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.6', '3.7', '3.8', '3.9']
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']

steps:
- name: Log reason (manual run only)
Expand Down
2 changes: 1 addition & 1 deletion src/ufonormalizer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1417,7 +1417,7 @@ def xmlConvertFloat(value):
if "." in string:
string = string.rstrip("0")
if string[-1] == ".":
return xmlConvertInt(int(value))
return xmlConvertInt(int(string[:-1]))
return string


Expand Down
1 change: 1 addition & 0 deletions tests/test_ufonormalizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1813,6 +1813,7 @@ def test_xmlConvertFloat(self):
self.assertEqual(xmlConvertFloat(1.0000000001), '1.0000000001')
self.assertEqual(xmlConvertFloat(1.00000000001), '1')
self.assertEqual(xmlConvertFloat(1.00000000009), '1.0000000001')
self.assertEqual(xmlConvertFloat(0.9999999999999999), '1')

def test_xmlConvertFloat_no_rounding(self):
import ufonormalizer
Expand Down

0 comments on commit cff786e

Please sign in to comment.