Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
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?
just convert it to int and divide by 100
int(price)/100
Add a comment
casting
Convert the price to string.
>>> price = "000245" >>> int(price)/100 2.45
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))
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.