可以将数字转换为字符串,然后使用字符串操作:
def numberWithoutRounding(num, precision=4): [beforeDecimal, afterDecimal] = str(num).split('.') return beforeDecimal + '.' + afterDecimal[0:precision]
>>> numberWithoutRounding(1.43219) '1.4321'