保留小数点
Keeping decimal point
目前我有以下代码:
nj_ = 0
j_ = 0
x_ = 1
nj_ = float(snum_ / (2 ** (j_ * 2)))
while nj_ > 0.4:
nj_ = snum_ / (2 ** (j_ * 2))
print " ", x_,"* sqrt(%d)" %nj_
j_ += 1
x_ = x_ * 2
输出如下:
通过因式分解求近似根:根为:
1 * sqrt(7761549)
2 * sqrt(1940387)
4 * sqrt(485096)
8 * sqrt(121274)
16 * sqrt(30318)
32 * sqrt(7579)
64 * sqrt(1894)
128 * sqrt(473)
256 * sqrt(118)
512 * sqrt(29)
1024 * sqrt(7)
2048 * sqrt(1)
4096 * sqrt(0)
如何设置输出格式以便打印带小数点的实际数字而不是四舍五入的数字?
尝试打印行:
print " ", x_,"* sqrt(%0.4f)" %nj_
目前我有以下代码:
nj_ = 0
j_ = 0
x_ = 1
nj_ = float(snum_ / (2 ** (j_ * 2)))
while nj_ > 0.4:
nj_ = snum_ / (2 ** (j_ * 2))
print " ", x_,"* sqrt(%d)" %nj_
j_ += 1
x_ = x_ * 2
输出如下:
通过因式分解求近似根:根为:
1 * sqrt(7761549)
2 * sqrt(1940387)
4 * sqrt(485096)
8 * sqrt(121274)
16 * sqrt(30318)
32 * sqrt(7579)
64 * sqrt(1894)
128 * sqrt(473)
256 * sqrt(118)
512 * sqrt(29)
1024 * sqrt(7)
2048 * sqrt(1)
4096 * sqrt(0)
如何设置输出格式以便打印带小数点的实际数字而不是四舍五入的数字?
尝试打印行:
print " ", x_,"* sqrt(%0.4f)" %nj_