def commas(number):
    """Insert commas in a number.

    Return the given number as a string with commas to separate
    the thousands positions.

    The number can be a float, int, long or string. Returns None for None.
    """
    if number is None:
        return None
    if not number:
        return str(number)
    number = list(str(number))
    if '.' in number:
        i = number.index('.')
    else:
        i = len(number)
    while 1:
        i -= 3
        if i <= 0 or number[i - 1] == '-':
            break
        number.insert(i, ',')
    return ''.join(number)