473,396 Members | 1,997 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Undocumented alternate form for %#f ?

I'm assuming this is by-design, but it doesn't appear to be documented:
'%8.f' % (-1) ' -1' '%#8.f' % (-1)

' -1.'
The docs list the alternate forms, but there isn't one listed for f/F. Itwould seem the alternate form for floating points is truncate & round the floating point value, but always display the . at the end. Is that correct?

Do you want to help develop Dynamic languages on CLR? (http://members.microsoft.com/careers...8-DC1B43134038)

Apr 28 '06 #1
1 1754
Dino Viehland wrote:
I'm assuming this is by-design, but it doesn't appear to be
documented:
'%8.f' % (-1) ' -1' '%#8.f' % (-1) ' -1.'
The docs list the alternate forms, but there isn't one listed for
f/F. It would seem the alternate form for floating points is
truncate & round the floating point value, but always display the .
at the end. Is that correct?


The Python % operator follows the C sprintf function pretty darn
closely in behaviour (hardly surprising really, though I've never
peeked at the implementation). Hence "man sprintf" can provide some
clues here. From man sprintf on my Linux box:

#
The value should be converted to an ``alternate form''. For o
conversions, the first character of the output string is made
zero (by prefixing a 0 if it was not zero already). For x and X
conversions, a non-zero result has the string `0x' (or `0X' for
X conversions) prepended to it. For a, A, e, E, f, F, g, and G
conversions, the result will always contain a decimal point,
even if no digits follow it (normally, a decimal point appears
in the results of those conversions only if a digit follows).
For g and G conversions, trailing zeros are not removed from the
result as they would otherwise be. For other conversions, the
result is undefined.

Hence, I don't think it's the # doing the truncating here, but it
certainly is producing the mandatory decimal point. If you get rid of
the "." in the specification, it uses the default decimal precision (6):
"%8f" % (-1) '-1.000000' "%#8f" % (-1)

'-1.000000'

No difference with the alternate specification here as the precision is
non-zero. Again, from man sprintf:

The precision
[snip]
If the precision is given as
just `.', or the precision is negative, the precision is taken to be
zero. This gives the minimum number of digits to appear for d, i, o,
u, x, and X conversions, the number of digits to appear after the radix
character for a, A, e, E, f, and F conversions, the maximum number of
significant digits for g and G conversions, or the maximum number of
characters to be printed from a string for s and S conversions.
HTH,

Dave.
--

Apr 28 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Joshua Beall | last post by:
Hi All, I've seen many references to the $_SERVER variable, which is set to the string 'on' when the client is connected via HTTPS rather than regular HTTP. However, I have been unable to find...
1
by: news | last post by:
Hi all, How do you implement alternate line colors in ms access datasheet view Regards Joe --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system...
1
by: jeffgeorge | last post by:
Using a bit of code to produce alternate line shading in a report. Seems it should work for a form as well but no luck. Does anyone have any ideas what I need to change or if it is even possible...
2
by: xmutantduck | last post by:
Hi, I am trying to write a program that can spawn forms when running in an alternate thread outside the main one. It however doesnt like to do anything related to the first thread when in the...
1
by: Eric Lindsay | last post by:
I am trying to understand the differences between and uses of persistent, default and alternate styles. I have read http://www.w3.org/TR/REC-html40/present/styles.html section 14.3.2 on...
5
by: Michael R | last post by:
Searching the net I've found a simple technique to add row numbers and alternate colors (for the even and the uneven row) to a continuous form. 1st step: Create a textbox, send it to background...
4
by: =?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?= | last post by:
I need to post a form to an alternate technology. I have created pop up windows that on post back will open a new window, but this uses get. I need to encode variables and POST to a new window on...
2
by: B. | last post by:
I am able to set the alternate row color using AlternatingRowsDefaultCellStyle. however, if my grid is not fully filled, the alternate row color will not apply for blank rows. How can I fill the...
5
by: OldBirdman | last post by:
Assume 2 tables tblP {Primary Table} tblP.Key {AutoNumber and all that} tblP.Name {Name of EE, Movie, Bird Species, or Whatever} tblA {Alternate Table} tblA.Key {AutoNumber and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.