DynamoDBNumberError when trying to insert a floating point number using python boto library

Code snippet:

conn = dynamo_connect()

company = Table("companydb",connection=conn)

companyrecord = {'company-slug':'www-google-com12','founding-year':1991, 'randomlist' :[1,2,3,4,5], 'randomdict' : {'a':[1,2,3],'b':'something','randomnumber':10.55} }

company.put_item(data=companyrecord)

I get the following error:

File "C:\Python27\lib\site-packages\boto\dynamodb2\items.py", line 329, in prepare_full
    final_data[key] = self._dynamizer.encode(value)
  File "C:\Python27\lib\site-packages\boto\dynamodb\types.py", line 279, in encode
    return {dynamodb_type: encoder(attr)}
  File "C:\Python27\lib\site-packages\boto\dynamodb\types.py", line 335, in _encode_m
    return dict([(k, self.encode(v)) for k, v in attr.items()])
  File "C:\Python27\lib\site-packages\boto\dynamodb\types.py", line 279, in encode
    return {dynamodb_type: encoder(attr)}
  File "C:\Python27\lib\site-packages\boto\dynamodb\types.py", line 305, in _encode_n
    raise DynamoDBNumberError(msg)
boto.dynamodb.exceptions.DynamoDBNumberError: BotoClientError: Inexact numeric for `10.55`
+4
source share
3 answers

Yes There are known issues in GitHub related to floating numbers, there can be 2 workarounds: first, if it’s convenient for you to store 10.5instead 10.55, then it will work fine, I think the other is to store the floating value as a String or integer, and then modulate it upon access .

, , '10.55' 10.55, , , float("10.55"), .

- . (, 2 ), 10.55 1055 ( 100, 2 ) 1055/100.0, 10.55.

+1

Python3 float.hex()/.fromhex() float :

. Pythons , float . , . .

- , @ZdaR str() float() .

[: ZdaR]

0

Decimal (str (your_number)). . https://github.com/boto/boto3/issues/665

0

All Articles