472,330 Members | 1,503 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Formatting floats

I'm trying to get floats formatted in exponent notation but with the
first non-zero number to the right of the decimal instead of to the left (
e.g. '-.107E2' instead of '-1.07E1'). Is this possible using the string
formatting operations?

--
Kevin Smith
Ke*********@sas.com
Jul 18 '05 #1
1 1466
Kevin Smith <Ke*********@sas.com> wrote in message news:<20********************@braeburn.themorgue.or g>...
I'm trying to get floats formatted in exponent notation but with the
first non-zero number to the right of the decimal instead of to the left (
e.g. '-.107E2' instead of '-1.07E1'). Is this possible using the string
formatting operations?

def formatFloat(x): .... mantissa, exponent = ('%e' % x).split('e')
.... mantissa = float(mantissa) / 10
.... exponent = int(exponent) + 1
.... return '%fe%d' % (mantissa, exponent)
.... formatFloat(-1.07E1)

'-0.107000e2'
Jul 18 '05 #2

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

Similar topics

10
by: Pascal | last post by:
Hello, I've a float number 123456789.01 and, I'de like to format it like this "123 456 789.01". Is this possible with % character?
6
by: David Sharp | last post by:
Once I've converted my floats to chars using STR, is there an easy way to put commas in separating the thousands. i.e. convert 53000000.12 to...
2
by: Victor Bien | last post by:
W3C says somewhere that tables should not be used for formatting columns etc. but that style sheets should be used instead. This has a major...
1
by: Richard | last post by:
I am new to C++ and I do not understand the formatting code very well. I need to format my output to look like this: Movie Name: ...
0
by: yb | last post by:
Hi, In CSS 2.1 Spec, section 9.4.1 says: "Floats, absolutely positioned elements, inline-blocks, table-cells, and elements with 'overflow'...
11
by: Russ | last post by:
I'd like to get output formatting for my own classes that mimics the built-in output formatting. For example, >>> x = 4.54 >>> print "%4.2f" % x...
6
by: Brian Schwartz | last post by:
Quick question related to Visual Studio's automatic code formatting. Often I like to write my variable declarations with spacing to line them up,...
2
by: victor.herasme | last post by:
Hi, i am building a little script and i want to output a series of columns more or less like this: 1 5 6 2 2 8 2 9 5 The matter is...
3
by: SimonPalmer | last post by:
anyone recommend a way of formatting floats with comma separators? e.g. 500000.00 -500,000.00
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

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.