I am using quite old Python 2.6.6 on Debian 6 (32-bit). Faced issue that any number with decimal 1 after dot represented like: 37.100000000000001
instead of 37.1
. Ok, I'd like to return it as in was introduced, i.e. 37.1
as float in JSON response. And I want in returned as float (otherwise '{0}'.format(number)
saves me).
UPD: sample taked on my system:
Python 2.6.6 (r266:84292, Dec 27 2010, 00:02:40)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> f = 37.1
>>> f
37.100000000000001
>>> round(f,2)
37.100000000000001
When JSON prepared it looks like:
>>> import json
>>> f = 37.1
>>> json.dumps({'value': f})
{ 'value': 37.100000000000001 }
But I want it be:
{ 'value': 37.1 }