469,366 Members | 2,045 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,366 developers. It's quick & easy.

float print formatting

hg
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

Feb 13 '07 #1
11 2583
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
Feb 13 '07 #2
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
Feb 13 '07 #3
hg
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

Feb 13 '07 #4
hg
NOSPAM plz wrote:
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
Sorry,

must be very slow or not enough coffee yet ... my purpose is to display a
justified report, so I format my floats into strings which I next draw in a
bitmap.

hg
Feb 13 '07 #5
hg wrote:
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 ?
The first integer specifies the total width:
>>"%05.2f" % 0
'00.00'

Peter
Feb 13 '07 #6
hg
Peter Otten wrote:
hg wrote:
>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 ?

The first integer specifies the total width:
>>>"%05.2f" % 0
'00.00'

Peter
Many thanks !

hg

Feb 13 '07 #7
On 2007-02-13, hg <hg@nospam.orgwrote:
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
The first number after the percent is the minimum width specifier
for the ENTIRE field.
s
>>'0.00'
len(s)
>>4
It is the MINIMUM width specifier for the entire field.

--
Neil Cerutti
The eighth-graders will be presenting Shakespeare's Hamlet in the church
basement on Friday at 7 p.m. The congregation is invited to attend this
tragedy. --Church Bulletin Blooper
Feb 13 '07 #8
hg
Neil Cerutti wrote:
The eighth-graders will be presenting Shakespeare's Hamlet in the church
basement on Friday at 7 p.m. The congregation is invited to attend this
tragedy. --Church Bulletin Blooper
;-) I like that !

hg

Feb 13 '07 #9
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
^^
That's the specifierfor how many total columns you want to use
(including the decimal point and all digits to either side).
Any clue ?
>>"%05.02f" % 0.0
'00.00'

--
Grant Edwards grante Yow! Yow!! "Janitor
at trapped in sewer uses ESP
visi.com to find decayed burger"!!
Feb 13 '07 #10
On 2007-02-13, hg <hg@nospam.orgwrote:
NOSPAM plz wrote:
>>Considering the float 0.0, I would like to print 00.00.

I tried '%02.02f' % 0.0 ... but I get 0.00
>Try this:

a = 45.45 # the floating number

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

must be very slow or not enough coffee yet...
Don't worry. I do know what you did wrong and how to fix it,
and I have absolutely no idea what "NOSPAM plz" is trying to
say either.

--
Grant Edwards grante Yow! I'm in a twist
at contest!! I'm in a
visi.com bathtub! It's on Mars!! I'm
in tip-top condition!
Feb 13 '07 #11
hg
Grant Edwards 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
^^
That's the specifierfor how many total columns you want to use
(including the decimal point and all digits to either side).
>Any clue ?
>>>"%05.02f" % 0.0
'00.00'

--
Grant Edwards grante Yow! Yow!! "Janitor
at trapped in sewer uses
ESP
visi.com to find decayed
burger"!!
Thanks

Feb 13 '07 #12

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Bernard Delmée | last post: by
2 posts views Thread by hpy_awad | last post: by
6 posts views Thread by Brian | last post: by
3 posts views Thread by Juergen | last post: by
22 posts views Thread by ashkaan57 | last post: by
9 posts views Thread by mathieu | last post: by
13 posts views Thread by helen.m.flynn | last post: by
5 posts views Thread by Selvam | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.