小编att*_*tti的帖子

Python:如何格式化固定宽度的数字?

让我们说吧

numbers = [ 0.7653, 10.2, 100.2325, 500.9874 ]
Run Code Online (Sandbox Code Playgroud)

我想通过改变小数位数来输出具有固定宽度的数字,以获得如下输出:

0.7653
10.200
100.23
500.98
Run Code Online (Sandbox Code Playgroud)

是否有捷径可寻?我一直在试图用各种%f%d配置,没有运气.

python string numbers fixed-width

6
推荐指数
2
解决办法
2504
查看次数

标签 统计

fixed-width ×1

numbers ×1

python ×1

string ×1