diff options
author | xi <xi@18f92427-320e-0410-9341-c67f048884a3> | 2007-03-22 16:13:32 +0000 |
---|---|---|
committer | xi <xi@18f92427-320e-0410-9341-c67f048884a3> | 2007-03-22 16:13:32 +0000 |
commit | 2d41f7115f32544c995687c96963b9ddc36c7f12 (patch) | |
tree | 22c31cef4f89513f8bbd975741c3234859799547 | |
parent | a316841d5fbcd81e1d94526c793d3590e44ab3ab (diff) | |
download | pyyaml-2d41f7115f32544c995687c96963b9ddc36c7f12.tar.gz |
Improve output of float values. Fix #49.
git-svn-id: http://svn.pyyaml.org/pyyaml/trunk@248 18f92427-320e-0410-9341-c67f048884a3
-rw-r--r-- | lib/yaml/representer.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/yaml/representer.py b/lib/yaml/representer.py index 072ed9b..1f4fe59 100644 --- a/lib/yaml/representer.py +++ b/lib/yaml/representer.py @@ -197,7 +197,16 @@ class SafeRepresenter(BaseRepresenter): elif data == -self.inf_value: value = u'-.inf' else: - value = unicode(repr(data)) + value = unicode(repr(data)).lower() + # Note that in some cases `repr(data)` represents a float number + # without the decimal parts. For instance: + # >>> repr(1e17) + # '1e17' + # Unfortunately, this is not a valid float representation according + # to the definition of the `!!float` tag. We fix this by adding + # '.0' before the 'e' symbol. + if u'.' not in value and u'e' in value: + value = value.replace(u'e', u'.0e', 1) return self.represent_scalar(u'tag:yaml.org,2002:float', value) def represent_list(self, data): |