浮动打印格式 [英] float print formatting

查看:79
本文介绍了浮动打印格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




考虑到浮点数0.0,我想打印00.00。


我试过''%02.02f'' %0.0 ...但我得到0.00


任何线索?


谢谢,


hg

解决方案

hg skrev:





考虑到浮点数0.0,我想打印00.00。


我试过''%02.02f''%0.0 ...但我得到了0.00


任何线索?


谢谢,


hg



试试这个:


a = 45.45#浮动数字


打印一些文字,

打印一份,

打印再打一些文字


或者只是这样:


打印一些文字,

打印45.45,

打印再写一些文字


希望它有所帮助:D $

Andreas

2007-02-13,hg< hg@nospam.orgwrote:





考虑到浮点数0.0,我想打印00.00。


我试过''%02.02f''%0.0 ...但我得到0.00


任何线索?



是的。与00.00相比,宽度(总数)是多少(0.00)?


-

Neil Cerutti


Neil Cerutti写道:


2007-02-13,hg< hg@nospam.orgwrote:
< blockquote class =post_quotes>
>

考虑到浮点数0.0,我想打印00.00。

我试过''%02.02f ''%0.0 ...但我得到0.00

任何线索?



是的。宽度(总)是0.00,与00.00相比?


-

Neil Cerutti



我不明白

s =''%02.02f''%0.0

s


>''0.00''



len(s)


> 4



Hi,

Considering the float 0.0, I would like to print 00.00.

I tried ''%02.02f'' % 0.0 ... but I get 0.00

Any clue ?

Thanks,

hg

解决方案

hg skrev:

Hi,

Considering the float 0.0, I would like to print 00.00.

I tried ''%02.02f'' % 0.0 ... but I get 0.00

Any clue ?

Thanks,

hg

Try this:

a = 45.45 # the floating number

print "some text",
print a,
print "some text again"

or just this:

print "some text",
print 45.45,
print "some text again"

Hope it helped :D

Andreas


On 2007-02-13, hg <hg@nospam.orgwrote:

Hi,

Considering the float 0.0, I would like to print 00.00.

I tried ''%02.02f'' % 0.0 ... but I get 0.00

Any clue ?

Yes. How wide (total) is "0.00", compared to "00.00"?

--
Neil Cerutti


Neil Cerutti wrote:

On 2007-02-13, hg <hg@nospam.orgwrote:

>Hi,

Considering the float 0.0, I would like to print 00.00.

I tried ''%02.02f'' % 0.0 ... but I get 0.00

Any clue ?


Yes. How wide (total) is "0.00", compared to "00.00"?

--
Neil Cerutti

I do not get it
s = ''%02.02f'' % 0.0
s

>''0.00''

len(s)

>4



这篇关于浮动打印格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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