Round a float to 2 decimal places in Python?

I need to send a float with two decimal places as a JSON object. I have tried using the Decimal class, but the last decimal place is still dropped when I print the object. How can I keep the float with two decimal places?

x = 2.00
message = { 'x': 2.00 } 
print(message)

To keep the float with two decimal places, you can use string formatting to convert the float into a string with two decimal places. Here’s an example:

x = 2.00
message = { 'x': '{:.2f}'.format(x) }
print(message)

The output will be:

{'x': '2.00'}