def number_round(num, decimal=2): """ 返回 浮点数num的四舍五入值 :param num: :param decimal: :return: """ if decimal == 1: ret = "{:.1f}".format(num) elif decimal == 2: ret = "{:.2f}".format(num) elif decimal == 3: ret = "{:.3f}".format(num) elif decimal == 4: ret = "{:.4f}".format(num) else: ret = "{:.2f}".format(num) return float(ret)
参考: