Skip to content

to_json float precision bug #15716

Closed
Closed
@amirshavit

Description

@amirshavit

xref #15864 for more tests

Code Sample, a copy-pastable example if possible

>>> pd.DataFrame([dict(a_float=0.99999999999999944)]).to_json(double_precision=14)
'{"a_float":{"0":1.0}}'
>>> pd.DataFrame([dict(a_float=0.99999999999999944)]).to_json(double_precision=15)
'{"a_float":{"0":0.1}}'

Problem description

...

Expected Output

'{"a_float":{"0":1.0}}'

Output of pd.show_versions()

INSTALLED VERSIONS ------------------ commit: None python: 2.7.12.final.0 python-bits: 64 OS: Linux OS-release: 4.4.0-66-generic machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_GB.UTF-8 LOCALE: None.None

pandas: 0.19.2
nose: 1.3.7
pip: 9.0.1
setuptools: 34.3.2
Cython: 0.24.1
numpy: 1.12.0
scipy: 0.18.1
statsmodelsdouble_precision: 0.6.1
xarray: None
IPython: 5.1.0
sphinx: 1.4.6
patsy: 0.4.1
dateutil: 2.6.0
pytz: 2016.10
blosc: None
bottleneck: 1.1.0
tables: 3.2.3.1
numexpr: 2.6.1
matplotlib: 1.5.3
openpyxl: 2.3.2
xlrd: 1.0.0
xlwt: 1.1.2
xlsxwriter: 0.9.3
lxml: 3.6.4
bs4: 4.5.1
html5lib: None
httplib2: 0.10.3
apiclient: 1.5.3
sqlalchemy: 1.1.2
pymysql: None
psycopg2: None
jinja2: 2.7.3
boto: 2.42.0
pandas_datareader: None

Metadata

Metadata

Assignees

No one assigned

    Labels

    IO JSONread_json, to_json, json_normalize

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions