我想使用"math.sqrt“,即使是像"4”这样的数字,我的输出也应该有4个小数点。有什么好玩的吗?!我使用了“圆形(num_sqrt,4)”,但它没有起作用。
我的输入是:1 2 3 19输出必须是: 1.0000 1.4142 1.7320 4.3588,我的输出是: 1.0 1.4142 1.7320 4.3588
发布于 2019-04-19 15:04:34
尝尝这个
from decimal import Decimal
import math
# example with sqrt function
y = Decimal(math.sqrt(4))
z = round(y, 4)
print(z) # output 2.0000
# First we take a float and convert it to a decimal
x = Decimal(16.0/7)
print(x)
# Then we round it to 4 places
output = round(x,4)
print(output) # outpun 2.2857https://stackoverflow.com/questions/55763795
复制相似问题