python - Number format with commas and one decimal -
this question has answer here:
i have number 1 decimal point such 123456.1
format 123,456.1
tried use locale format number unable work
instead used following:
def format(n): r = [] i, c in enumerate(reversed(str(n))): if , (not (i % 3)): r.insert(0, ',') r.insert(0, c) return ''.join(r)
which results in 1,234,56.1
use string formatting.
>>> '{:,}'.format(123456.1) '123,456.1'
Comments
Post a Comment