473,326 Members | 2,111 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,326 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 1485
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 53,000,000.12 I'm thinking I'll have to do it...
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 unlearning/relearning implications for me (and just...
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: "Death Grip" Adult Tickets Sold: ...
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' other than 'visible' establish new block formatting...
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 4.54 In other words, if I substitute a...
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, like this (not sure if this spacing will come out...
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 that i don't know in advance how many columns...
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: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.