1
%のx.yfに浮かぶと私が渡って来ている:私は決して前に整数で%.4f
を見てきました文字列の書式は、私はPythonの</em><em>自然言語処理とを読んだ
count, total = 3205, 9375
"accuracy for %d words: %2.4f%%" % (total, 100 * count/total)
小数点の
print('%.4f' %(100*count/total))
print('%0.4f' %(100*count/total))
print('%1.4f' %(100*count/total))
print('%2.4f' %(100*count/total))
エトセトラ:それで遊んで、次のすべてに同じこと(34.1867
)を印刷します。小数点の前の値は何をしますか?
それは、小数点の前に少なくとも2つの数値を意味し、プレースメントが既に存在している - 10より小さい値で試してみるか、テンプレート内の数字を2より大きくする。docs:https://docs.python.org/3/library/stdtypes.html#printfを参照してください。 -style-string-formatting – jonrsharpe
https://pyformat.info/#number_padding –
@jonrsharpe itパディングは文字の総数、すなわち小数点の前後の数字と小数点自体に基づいているようです。したがって、 '%7.4f'は' 34.1867'を生成しますが '%8.4f'は' 34.1867'を生成します。 – sn8wman