www/src/py_string.js
function(val, upper, flags){
    val = _float_helper(val, flags),
        v = val.toString(),
        v_len = v.length,
        dot_idx = v.indexOf('.')
    if(dot_idx < 0){dot_idx = v_len}
    if(val < 1 && val > -1){
        var zeros = leading_zeros.exec(v),
            numzeros
        if(zeros){
            numzeros = zeros[1].length
        }else{
            numzeros = 0
        }
        if(numzeros >= 4){
            val = format_sign(val, flags) + format_float_precision(val, upper,
                flags, _floating_g_exp_helper)
            if(!flags.alternate){
                var trl = trailing_zeros.exec(val)
                if(trl){
                    val = trl[1].replace(trailing_dot, "") + trl[3]  // remove trailing
                }
            }else{
                if(flags.precision <= 1){
                    val = val[0] + "." + val.substring(1)
                }
            }
            return format_padding(val, flags)
        }
        flags.precision = (flags.precision || 0) + numzeros
        return format_padding(format_sign(val, flags) +
            format_float_precision(val, upper, flags,
                function(val, precision) {
                    return val.toFixed(min(precision, v_len - dot_idx) +
                        numzeros)
                }),
            flags
        )
    }

    if(dot_idx > flags.precision){
        val = format_sign(val, flags) + format_float_precision(val, upper,
            flags, _floating_g_exp_helper)
        if(! flags.alternate){
            var trl = trailing_zeros.exec(val)
            if(trl){
                val = trl[1].replace(trailing_dot, "") + trl[3]  // remove trailing
            }
        }else{
            if(flags.precision <= 1){
                val = val[0] + "." + val.substring(1)
            }
        }
        return format_padding(val, flags)
    }
    return format_padding(format_sign(val, flags) +
        format_float_precision(val, upper, flags,
            function(val, precision) {
                if(!flags.decimal_point){
                    precision = min(v_len - 1, 6)
                }else if (precision > v_len){
                    if(! flags.alternate){
                        precision = v_len
                    }
                }
                if(precision < dot_idx){
                    precision = dot_idx
                }
                return val.toFixed(precision - dot_idx)
            }),
        flags
    )
}
function(val, upper, flags){
    val = _float_helper(val, flags),
        v = val.toString(),
        v_len = v.length,
        dot_idx = v.indexOf('.')
    if(dot_idx < 0){dot_idx = v_len}
    if(val < 1 && val > -1){
        var zeros = leading_zeros.exec(v),
            numzeros
        if(zeros){
            numzeros = zeros[1].length
        }else{
            numzeros = 0
        }
        if(numzeros >= 4){
            val = format_sign(val, flags) + format_float_precision(val, upper,
                flags, _floating_g_exp_helper)
            if(!flags.alternate){
                var trl = trailing_zeros.exec(val)
                if(trl){
                    val = trl[1].replace(trailing_dot, "") + trl[3]  // remove trailing
                }
            }else{
                if(flags.precision <= 1){
                    val = val[0] + "." + val.substring(1)
                }
            }
            return format_padding(val, flags)
        }
        flags.precision = (flags.precision || 0) + numzeros
        return format_padding(format_sign(val, flags) +
            format_float_precision(val, upper, flags,
                function(val, precision) {
                    return val.toFixed(min(precision, v_len - dot_idx) +
                        numzeros)
                }),
            flags
        )
    }

    if(dot_idx > flags.precision){
        val = format_sign(val, flags) + format_float_precision(val, upper,
            flags, _floating_g_exp_helper)
        if(! flags.alternate){
            var trl = trailing_zeros.exec(val)
            if(trl){
                val = trl[1].replace(trailing_dot, "") + trl[3]  // remove trailing
            }
        }else{
            if(flags.precision <= 1){
                val = val[0] + "." + val.substring(1)
            }
        }
        return format_padding(val, flags)
    }
    return format_padding(format_sign(val, flags) +
        format_float_precision(val, upper, flags,
            function(val, precision) {
                if(!flags.decimal_point){
                    precision = min(v_len - 1, 6)
                }else if (precision > v_len){
                    if(! flags.alternate){
                        precision = v_len
                    }
                }
                if(precision < dot_idx){
                    precision = dot_idx
                }
                return val.toFixed(precision - dot_idx)
            }),
        flags
    )
}
gG