def format_number(value, max_digits, decimal_places):
    if value is None:
        return None
    if isinstance(value, decimal.Decimal):
        context = decimal.getcontext().copy()
        if max_digits is not None:
            context.prec = max_digits
        if decimal_places is not None:
            value = value.quantize(decimal.Decimal(".1") ** decimal_places, context=context)
        else:
            context.traps[decimal.Rounded] = 1
            value = context.create_decimal(value)
        return "{:f}".format(value)
    if decimal_places is not None:
        return "%.*f" % (decimal_places, value)
    return "{:f}".format(value)
Constructor.
dataset/ETHPy150Open django/django/django/db/backends/utils.py/format_number--crossover with--dataset/ETHPy150Open AppScale/appscale/AppServer/google/appengine/tools/appcfg.py/UploadBatcher.__init__