Your task is to convert a given number into a string with commas added for easier readability.  The number should be rounded to 3 decimal places and the commas should be added at intervals of three digits before the decimal point. There does not need to be a comma at the end of the number.

You will receive both positive and negative numbers.

## Examples

```python
commas(1) == "1"
commas(1000) == "1,000"
commas(100.2346) == "100.235"
commas(1000000000.23) == "1,000,000,000.23"
commas(-1) == "-1"
commas(-1000000.123) == "-1,000,000.123"
```

Source: codewars | Difficulty: EASY
Tags: Fundamentals

Starter code: def commas(num):
	

Solutions:
def commas(num):
	return '{:,.3f}'.format(num).rstrip('0').rstrip('.')


def commas(num):
	return f'{num:,.3f}'.rstrip('0').rstrip('.')


import re

def commas(num):
	if isinstance(num, int):
		return format(num, ',')
	else:
		return re.sub('\\.?0+$', '', format(round(num, 3), ',.3f'))


def commas(num):
	i = round(num, 3)
	f = int(i)
	return f'{(f if f == i else i):,}'


def commas(s):
	s = round(s, 3)
	return format([int(s), s][s != int(s)], ',')


def commas(num):
	number = float(num)
	return f'{number:,.0f}' if number.is_integer() else f'{number:,.3f}'.rstrip('0').rstrip('.')


def commas(num):
	n = format(round(num, 3), ',').split('.')
	return n[0] + '.' + n[1] if len(n) > 1 and n[1] != '0' else n[0]


def commas(n):
	try:
		n = round(n, 3)
	except:
		print('Error')
	res = '{:,}'.format(n)
	print(res)
	if res.endswith('.0'):
		return res[:-2]
	return res


from re import sub
commas = lambda num: (lambda num: sub('(\\d)(?=(\\d{3})+(?!\\d))', '\\g<1>,', str(int(num) if num % 1 == 0 else num)))(round(num, 3))