精确四舍五入123456789import decimaldef round_up(x, y): """ 四舍五入 :param x: 具体数值 type: str :param y: 保留小数位数 type: str example: "0.01" 取整 “1.0” :return: str """ return decimal.Decimal(x).quantize(decimal.Decimal(y), rounding=decimal.ROUND_UP) 时间戳转换当地时间1234567891011import timeimport datetimedef timestamp_to_localtime(timestamp): """ 时间戳转换当地时间 :param timestamp: 时间戳 :return: str """ time_local = time.localtime(timestamp) dt = time.strftime("%Y-%m-%d %H:%M:%S", time_local) return dt