def format(number, decimal_sep, decimal_pos, grouping=0, thousand_sep=''):
    use_grouping = settings.USE_L10N and settings.USE_THOUSAND_SEPARATOR and grouping
    # Make the common case fast:
    if isinstance(number, int) and not use_grouping and not decimal_pos:
        return mark_safe(unicode(number))
    # sign
    if float(number) < 0:
        sign = '-'
    else:
        sign = ''
    str_number = unicode(number)
    if str_number[0] == '-':
        str_number = str_number[1:]
    # decimal part
    if '.' in str_number:
        int_part, dec_part = str_number.split('.')
        if decimal_pos:
            dec_part = dec_part[:decimal_pos]
    else:
        int_part, dec_part = str_number, ''
    if decimal_pos:
        dec_part = dec_part + ('0' * (decimal_pos - len(dec_part)))
    if dec_part: dec_part = decimal_sep + dec_part
    # grouping
    if use_grouping:
        int_part_gd = ''
        for cnt, digit in enumerate(int_part[::-1]):
            if cnt and not cnt % grouping:
                int_part_gd += thousand_sep
            int_part_gd += digit
        int_part = int_part_gd[::-1]
    return sign + int_part + dec_part
Unitiliy float encoding which clamps floats close to 0 and 1 and uses %g instead of repr().
dataset/ETHPy150Open AppScale/appscale/AppServer/google/appengine/_internal/django/utils/numberformat.py/format--crossover with--dataset/ETHPy150Open turbulenz/turbulenz_tools/turbulenz_tools/utils/json_utils.py/float_to_string