I want to represent money which is usually to 2DP and I add up items using float values but whenever I have a value that is similar to the one used it only converts it to a string to 1DP.

This seems like its going to be annoying to work around. I'm thinking of using a regular expression and an if statement to add a "0" to the end if the string is only to 1DP but i was wondering if there were any other methods I could use.

Any ideas?

number = 0.60

string = "0.60"

stringofnumber = str(number)

print number

print string

print stringofnumber

Something you can look at,for doing financial calculations look at Decimal module.

>>> number = 0.60
>>> print '%.2f' % number

>>> from decimal import *
>>> Decimal('0.60')
>>> Decimal('0.60') + Decimal('0.60')
>>> print Decimal('0.60') + Decimal('0.60')
This post was concise and to the point with good examples
This question has already been answered. Start a new discussion instead.