我希望昏迷后始终有 5 个数字。
示例: 我的数据是这样的 105.56565 105. 165.54......
我想要相同的长度,如下所示:105.56565 105.00000 165.54000....
脚本:
from pylab import*
from rtlsdr import*
from bluetooth import*
import sys
#configure device
sdr= RtlSdr()
sdr.sample_rate=double(sys.argv[3])
sdr.gain=double(sys.argv[2])
sdr.center_freq=double(sys.argv[1])
#Bluetooth connection
server_sock=BluetoothSocket(RFCOMM)
server_sock.bind(("",PORT_ANY))
server_sock.listen(1)
port=server_sock.getsockname()[1]
uuid="94f39d29-7d6d-437d-973b-fba39e49d4ee"
client_sock,client_info=server_sock.accept()
while(1):
samples=sdr.read_samples(256*1024)
result=psd(samples,NFFT=1024, Fs=sdr.sample_rate/1e6, Fc=sdr.center_freq*1e6/1e6)
freq=result[1]/1e6
value_freq=str(freq)[1:-1]
print format(freq, '%5f') // he do not work
最佳答案
在最后一行,我认为你想做:
print "%5f" % freq
希望这有帮助!
关于python - 在 Python 中将输出格式化为固定精度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44954859/