如何将浮点数显示到小数点后 4 位,而不向上或向下舍入?

How to display float numbers to 4 decimal places, without rounding up or down?

我试图只显示浮点数的 4 位小数,而不对数字进行四舍五入。例如,我找到的答案以输出向上或向下舍入的方式解释它;

In: 1.23456789
Out: 1.2346
but my desired output is: 1.2345
from math import sqrt
n = int(input())
list1=[]
for i in range (0,n):
    list1.append(input())

for i in range (0,n):
    print("{0:.4f}".format(sqrt(int(list1[i]))))

术语是截断,例如,这是将x截断为小数点后四位的代码。

x = 1.23456789
print(int(x * 10000)/10000)

您仍然需要格式化,因为浮点数可能会出现一些不一致。