Reputation: 23811
I'm trying to use a string of a decimal, but I am getting an unwanted "0.". For example:
age = .01
print 'test%s'%(age)
print 'test' + str(age)
These both return 'test0.01', but I want 'test.01'. I know there is a simple solution. Any thoughts?
Upvotes: 1
Views: 126
Reputation: 11205
age = .01
print 'test%s' % str(age)[1:] if 0<age<1 else str(age)
Upvotes: 2
Reputation: 212885
age = .01
print 'test' + str(age).lstrip('0')
Works for age > 1.0
as well.
Upvotes: 6