Format numbers with commas
[mevemon] / package / src / util.py
1 #Random helpful functions for mevemon
2  
3 def comma(d):
4     """
5     Converts a number in the format 1234567 to 1,234,567
6     """
7     s = '%0.2f' % d
8     
9     a,b = s.split('.')
10     l = []
11     while len(a) > 3:
12         l.insert(0,a[-3:])
13         a = a[0:-3]
14     if a:
15         l.insert(0,a)
16
17     if type(d) is int:
18         return ','.join(l)
19     else:
20         return ','.join(l)+'.'+b
21