Commits

João Pedro Francese committed 9298b67

[v0.2.19] Fixing representation of very small Decimals in ExtendedJSONEncoder.

  • Participants
  • Parent commits 1c10d81

Comments (0)

Files changed (2)

File inoa/utils/json.py

 class ExtendedJSONEncoder(simplejson.JSONEncoder):
     def default(self, obj):
         if isinstance(obj, Decimal):
-            return str(obj)
+            exponent = obj.as_tuple()[2]
+            if exponent < 0:
+                return "%%.%df" % -exponent % obj
+            else:
+                return "%d.0" % obj
         if isinstance(obj, datetime) or isinstance(obj, date) or isinstance(obj, time):
             return obj.isoformat()
         return super(ExtendedJSONEncoder, self).default(obj) 
 
 setup(
     name='django-inoa',
-    version='0.2.18',
+    version='0.2.19',
     author='Inoa',
     author_email='django@inoa.com.br',
     packages=packages,