summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRolf Wojtech <rolf@wojtech.de>2018-03-21 16:37:39 +0100
committerRolf Wojtech <rolf@wojtech.de>2018-03-21 16:37:39 +0100
commit66b44b72d4be2a975c45d1d84bec80b10e3184da (patch)
tree65771d2bb573ed20a6f545dbb23fb3d6581a1e8c
parent0bda7fa8499b6c802d6246435524b839e9a8ba4c (diff)
downloadruamel.yaml-66b44b72d4be2a975c45d1d84bec80b10e3184da.tar.gz
Attempted fix for scientic notation parsing
-rw-r--r--_test/test_float.py11
-rw-r--r--representer.py2
2 files changed, 12 insertions, 1 deletions
diff --git a/_test/test_float.py b/_test/test_float.py
index f9d060d..3fda083 100644
--- a/_test/test_float.py
+++ b/_test/test_float.py
@@ -134,6 +134,17 @@ class TestFloat:
- 250e6
""")
+ def test_round_trip_exp_05(self):
+ data = round_trip("""\
+ - 3.0517578123e-56
+ - 3.0517578123E-56
+ - 3.0517578123e-056
+ - 3.0517578123E-056
+ """)
+ print(data)
+ for d in data:
+ assert 3.0517578122e-56 < d < 3.0517578124e-56
+
def test_yaml_1_1_no_dot(self):
with pytest.warns(MantissaNoDotYAML1_1Warning):
round_trip_load("""\
diff --git a/representer.py b/representer.py
index 25e53b9..9163637 100644
--- a/representer.py
+++ b/representer.py
@@ -782,7 +782,7 @@ class RoundTripRepresenter(SafeRepresenter):
value += u'0'
else:
# exponent
- m, es = u'{:{}e}'.format(data, data._width).split('e')
+ m, es = u'{:{}.{}e}'.format(data, data._width, data._width - data._prec).split('e')
w = data._width if data._prec > 0 else (data._width + 1)
if data < 0:
w += 1