473,508 Members | 2,355 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2788
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1532
by: Bernard Delmée | last post by:
Is there a simple way to modify the default sprintf mask used for floats ? (eg something like sys.float_mask = '%.2f') I've tried assigning to float.__dict__, but that's apparently not allowed.
3
146428
by: David Sharp | last post by:
I'm trying to find a way to format a FLOAT variable into a varchar in SQL Server 2000 but using CAST/CONVERT I can only get scientific notation i.e. 1e+006 instead of 1000000 which isn't really...
2
9510
by: hpy_awad | last post by:
formatting float variables to fprintf has error to my writing to output file called rental and I do not the reason that a rabish is written to the file instead of the actual input screen values ? ...
6
2451
by: Brian | last post by:
Hello all, I am a bit stuck with a float formatting issue. What I want to do is print a float to the screen with each line showing one more decimal place. Here is a code snip that may explain...
3
1950
by: Juergen | last post by:
hi, I've got a problem sending floating point values to an corba server. With other datatyes like short or string it works fine. So having this idl file : module Example{ interface User{
22
51405
by: ashkaan57 | last post by:
Hi, I am trying to put text on left and right side of the page and used: <div> <span>blah blah</span> <span style="float:right">blah blah</span> </div> The 2nd text does go to the right but the...
9
6330
by: mathieu | last post by:
Hi, I know I am doing something stupid here, but it's friday night and I cannot see what is the issue here: Thanks, -Mathieu #include <iostream>
13
2416
by: helen.m.flynn | last post by:
Hi I'm very much a beginner with Python. I want to write a function to convert celcius to fahrenheit like this one: def celciusToFahrenheit(tc): tf = (9/5)*tc+32 return tf I want the answer...
5
2615
by: Selvam | last post by:
Hi All, I am getting exponent value when doing float arithmetic in C++. Instead of that I need accurate value. float amount = 0.0f; float x = 0.99999976f; amount= 1.0f - x; I am getting...
0
7224
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7118
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7379
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7493
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5625
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3192
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3180
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1550
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.