(f, p=0)
return string
Set float precision and trim precision zeros.
Set float precision and trim precision zeros.
Set float precision and trim precision zeros .
def fmt_float(f, p=0):
    """Set float precision and trim precision zeros."""

    string = str(
        decimal.Decimal(f).quantize(decimal.Decimal('0.' + ('0' * p) if p > 0 else '0'), decimal.ROUND_HALF_UP)
    )

    m = re_float_trim.match(string)
    if m:
        string = m.group('keep')
        if m.group('keep2'):
            string += m.group('keep2')
    return string
def fmt_float ( f , p = 0 ) : string = str ( decimal . Decimal ( f ) . quantize ( decimal . Decimal ( '0.' + ( '0' * p ) if p > 0 else '0' ) , decimal . ROUND_HALF_UP ) ) m = re_float_trim . match ( string ) if m : string = m . group ( 'keep' ) if m . group ( 'keep2' ) : string += m . group ( 'keep2' ) return string