Removing Trailing Zeros in Python [duplicate]

Updated Generalized to maintain precision and handle unseen values: import decimal import random def format_number(num): try: dec = decimal.Decimal(num) except: return ‘bad’ tup = dec.as_tuple() delta = len(tup.digits) + tup.exponent digits=””.join(str(d) for d in tup.digits) if delta <= 0: zeros = abs(tup.exponent) – len(tup.digits) val=”0.” + (‘0’*zeros) + digits else: val = digits[:delta] + (‘0’*tup.exponent) … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)