Reputation: 1
I have a text file that has a price column like 000245 and like 001245. I want to format the strings as 2.45 and 12.45?
Upvotes: 0
Views: 73
Reputation: 6090
If you work with strings and want to get a string back:
s = '000245'
s = s.lstrip('0')
print (s[:-2]+'.'+s[-2:])
Output (as string):
2.45
Otherwise, still to preserve the variable type:
print (str(int(s)/100))
Upvotes: 0
Reputation: 131
Convert the price to string.
>>> price = "000245"
>>> int(price)/100
2.45
Upvotes: 1