From 83b4f8a348cf05c7fcd933001aac4215322210c2 Mon Sep 17 00:00:00 2001 From: Uiri Date: Wed, 12 Apr 2017 13:18:15 -0400 Subject: [PATCH] Fix #63: Strip leading 0 in exponent part --- toml.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/toml.py b/toml.py index 4d01e7e..e08dc18 100644 --- a/toml.py +++ b/toml.py @@ -786,7 +786,7 @@ def _dump_value(v): unicode: lambda: _dump_str(v), list: lambda: _dump_list(v), bool: lambda: str(v).lower(), - float: lambda: str(v), + float: lambda: _dump_float(v), datetime.datetime: lambda: v.isoformat()[:19]+'Z', } # Lookup function corresponding to v's type @@ -794,9 +794,6 @@ def _dump_value(v): # Evaluate function (if it exists) else return v return dump_fn() if dump_fn is not None else v - - - def _dump_str(v): v = "%r" % v if v[0] == 'u': @@ -809,7 +806,6 @@ def _dump_str(v): v = v.replace("\\x", "\\u00") return str('"'+v+'"') - def _dump_list(v): t = [] retval = "[" @@ -826,3 +822,6 @@ def _dump_list(v): t = s retval += "]" return retval + +def _dump_float(v): + return "{0:.16g}".format(v).replace("e+0", "e+").replace("e-0", "e-")