def group(nb, digits=0):
    """Transforms a number into a string with a thousand separator.

    .. code-block:: python

        pycof.group(nb, digits=0)

    :Parameters:
        * **nb** (:obj:`float`): Number to be transformed.
        * **digits** (:obj:`int`): Number of digits to round.
    
    :Example:
        >>> pycof.group(12345)
        ... '12,345'
        >>> pycof.group(12345.54321, digits=3)
        ... '12,345.543'

    :Returns:
        * :obj:`str`: Transformed number.
    """
    s = '%d' % nb
    groups = []
    if digits > 0:
        dig = '.' + str(nb).split('.')[1][:digits]
    else:
        dig = ''
    while s and s[-1].isdigit():
        groups.append(s[-3:])
        s = s[:-3]
    return s + ','.join(reversed(groups)) + dig
