python中精确输出JSON浮点数的方法

901次阅读  |  发布于5年以前

有时需要在JSON中使用浮点数,比如价格、坐标等信息。但python中的浮点数相当不准确, 例如下面的代码:

复制代码 代码如下:

!/usr/bin/env python

import json as json

data = [ 0.333, 0.999, 0.1 ]
print json.dumps(data)

Copyright© 2013-2020

All Rights Reserved 京ICP备2023019179号-8