THRIFT-3376 C# and Python JSON protocol double values lose precision
Client: C#, Python, C++, Ruby
Patch: Nobuaki Sukegawa <nsukeg@gmail.com>

This closes #643
diff --git a/lib/py/src/protocol/TJSONProtocol.py b/lib/py/src/protocol/TJSONProtocol.py
index 9e25f67..7807a6c 100644
--- a/lib/py/src/protocol/TJSONProtocol.py
+++ b/lib/py/src/protocol/TJSONProtocol.py
@@ -176,9 +176,9 @@
     self.context.write()
     self.trans.write(json.dumps(string, ensure_ascii=False))
 
-  def writeJSONNumber(self, number):
+  def writeJSONNumber(self, number, formatter='{}'):
     self.context.write()
-    jsNumber = str(number)
+    jsNumber = formatter.format(number)
     if self.context.escapeNum():
       jsNumber = "%s%s%s" % (QUOTE, jsNumber, QUOTE)
     self.trans.write(jsNumber)
@@ -467,7 +467,8 @@
     self.writeJSONNumber(i64)
 
   def writeDouble(self, dbl):
-    self.writeJSONNumber(dbl)
+    # 17 significant digits should be just enough for any double precision value.
+    self.writeJSONNumber(dbl, '{:.17g}')
 
   def writeString(self, string):
     self.writeJSONString(string)