0

I have a dictionary like

>> dic = {'yearly': 79.00, 'monthly': 59.00}

when the dic is printed the, it removes the last zero from the decimal number.

>> print dic
>> {'monthly': 59.0, 'yearly': 79.0}

How to get the original value as 59.00 not as 59.0 ?

navyad
  • 3,752
  • 7
  • 47
  • 88
  • possible duplicate of [Limiting floats to two decimal points](http://stackoverflow.com/questions/455612/limiting-floats-to-two-decimal-points) – David Nov 05 '14 at 06:07
  • another option would be to use the `decimal.Decimal` class – shx2 Nov 05 '14 at 06:27

1 Answers1

0

when you print a number, you could do

x = 5
print '%.2f' % x

where the 2 specifies u want 2 decimal place

alternatively, the more updated/versatile version is

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

if you really want your dict object to print nicely, you could create a custom class that specifies the __str__ function to print the dict however you want to print it

conrad
  • 1,783
  • 14
  • 28