我工作的一个代码,并有我在的形式获取数据:在Python与数精度浮点数格式滞留小数
k=[{'item_id': '43381702', 'length': {'_exp': -2, '_is_special': False, '_int': '0', '_sign': 0}, 'height': {'_exp': -2, '_is_special': False, '_int': '0', '_sign': 0}, 'width': {'_exp': -2, '_is_special': False, '_int': '0', '_sign': 0}, 'unitweight': {'_exp': -3, '_is_special': False, '_int': '3000', '_sign': 0}, 'quantity': 1}]
而且据预计,当我写
float(k[0]['unitweight'])
它应该被转换成浮点数。但它是给予
TypeError: float() argument must be a string or a number
如预期。我很困惑,因为数据的格式与python十进制模块中实现的形式相同。有没有什么办法(单线)我可以通过哪些方式将数据转换为浮点数?
'is_special'不是'Decimal'的属性 – jamylak
我认为它是一个数字的属性。查看[提示](http://www.itmaybeahack.com/homepage/books/nonprog/html/p13_modules/p13_c03_decimal.html#rounding-known-as-quantization)关于attribue错误和此[链接](http:/ /mail.python.org/pipermail/python-checkins/2007-November/063656.html)也显示了python代码中的修改。 – tusharmakkar08