Issue #222 new

Float fields decimal problem

Ariel Camino
created an issue

In python <= 2.6, float fields are shown like this in the JSON response:

{{{

0.2 0.20000000000000001 }}}

The solution is the same as decimal fields, convert it to strings: {{{ diff -r 7c90898072ce piston/emitters.py --- a/piston/emitters.py Fri Mar 30 18:12:21 2012 -0400 +++ b/piston/emitters.py Fri Jul 13 12:47:40 2012 -0300 @@ -119,6 +119,8 @@ ret = _dict(thing, fields) elif isinstance(thing, decimal.Decimal): ret = str(thing) + elif isinstance(thing, float): + ret = str(thing) elif isinstance(thing, Model): ret = _model(thing, fields) elif isinstance(thing, HttpResponse): }}}

Tested in python 2.6 and 2.7

Comments (1)

  1. Log in to comment