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