对齐float并指定字符串格式的精度 [英] align float and specify precision in string formatting

查看:104
本文介绍了对齐float并指定字符串格式的精度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  In [16]:print{:> 20} {:0.2格式(,34)
34.00

但是我想这样做只用一个格式的参数,我该怎么写呢?

解决方案

 >>>打印{:> 25.2f}。格式(34)
34.00

,我的空间可能与你的空间不同(我的空间与你的例子相同)。



这是对我来说:


I have this working test code:

In [16]: print "{:>20}{:0.2f}".format("", 34)
                34.00

but I would like to do it with just one argument in format, how do I write that?

解决方案

Is this what you intended?

>>> print "{:>25.2f}".format(34)
                34.00

Note, my spaces may be different to yours (the spaces I have is the same distance from your example).

This is what appears for me:

这篇关于对齐float并指定字符串格式的精度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆