469,352 Members | 1,697 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

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 1435
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by Pascal | last post: by
6 posts views Thread by David Sharp | last post: by
1 post views Thread by Richard | last post: by
reply views Thread by yb | last post: by
11 posts views Thread by Russ | last post: by
6 posts views Thread by Brian Schwartz | last post: by
2 posts views Thread by victor.herasme | last post: by
3 posts views Thread by SimonPalmer | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | 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.