473,224 Members | 1,973 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,224 software developers and data experts.

exponential float formmating

Hi,

For compatibility reasons with an old program I have to format string
in exponential
format with the following format

0.xxxxxE-yy

This means that the number start always by 0 and after the exponent
there should be alway the sing and 2 number for the exponent.

for example 13 shoud be 0.13000E+02
I always get 1.30000E001

Thanks,

Zunbeltz

Sep 7 '07 #1
5 7066
On Fri, 07 Sep 2007 06:08:19 -0700, zunbeltz wrote:
For compatibility reasons with an old program I have to format string
in exponential format with the following format

0.xxxxxE-yy

This means that the number start always by 0 and after the exponent
there should be alway the sing and 2 number for the exponent.

for example 13 shoud be 0.13000E+02
I always get 1.30000E001
I don't know if this is platform dependent but this works for me:

In [41]: '%e' % 1.3
Out[41]: '1.300000e+00'

In [42]: ('%e' % 1.3).upper()
Out[42]: '1.300000E+00'

Ciao,
Marc 'BlackJack' Rintsch
Sep 7 '07 #2
On 7 sep, 15:42, Marc 'BlackJack' Rintsch <bj_...@gmx.netwrote:
On Fri, 07 Sep 2007 06:08:19 -0700, zunbeltz wrote:
For compatibility reasons with an old program I have to format string
in exponential format with the following format
0.xxxxxE-yy
This means that the number start always by 0 and after the exponent
there should be alway the sing and 2 number for the exponent.
for example 13 shoud be 0.13000E+02
I always get 1.30000E001

I don't know if this is platform dependent but this works for me:

In [41]: '%e' % 1.3
Out[41]: '1.300000e+00'

In [42]: ('%e' % 1.3).upper()
Out[42]: '1.300000E+00'

Ciao,
Marc 'BlackJack' Rintsch
I am working in windows I get
>>'%e' % 13
'1.300000e+001'

In all cases I need the number to start with 0
0.13000E+01

Sep 7 '07 #3
On Sep 7, 6:08 am, zunbe...@gmail.com wrote:
Hi,

For compatibility reasons with an old program I have to format string
in exponential
format with the following format

0.xxxxxE-yy

This means that the number start always by 0 and after the exponent
there should be alway the sing and 2 number for the exponent.

for example 13 shoud be 0.13000E+02
I always get 1.30000E001

Perhaps it would then be worthwhile to subclass float?

import math
class ffloat(float):
"""Formatted float?"""
def __str__(self):
prefix = (self < 0) and '-' or ''
fabs = math.fabs(self)
exponent = math.floor(math.log10(fabs)) + 1
significand = fabs / math.pow(10, exponent)
width = exponent 0 and 2 or 3
return '%s%fE%0*d' % (prefix,significand,width,exponent)
f = ffloat(13)
print f
f = ffloat(-12.23e-4)
print f
--
Hope this helps,
Steven

Sep 7 '07 #4
On Fri, 07 Sep 2007 13:42:30 +0000, Marc 'BlackJack' Rintsch wrote:
On Fri, 07 Sep 2007 06:08:19 -0700, zunbeltz wrote:
>For compatibility reasons with an old program I have to format string
in exponential format with the following format

0.xxxxxE-yy

This means that the number start always by 0 and after the exponent
there should be alway the sing and 2 number for the exponent.

for example 13 shoud be 0.13000E+02
I always get 1.30000E001

I don't know if this is platform dependent but this works for me:

In [41]: '%e' % 1.3
Out[41]: '1.300000e+00'

In [42]: ('%e' % 1.3).upper()
Out[42]: '1.300000E+00'
Alas, you've missed the Original Poster's requirement that the formatted
number always starts with 0.

Also, an easier way to format floats with a capital E is to use %E
instead of %e.

I don't believe there is a standard way of formatting floats with a
leading zero.
--
Steven.
Sep 8 '07 #5
In message <11**********************@50g2000hsm.googlegroups. com>,
zu******@gmail.com wrote:
In all cases I need the number to start with 0
0.13000E+01
So why not move the decimal point left one, and add one to the exponent.
Sep 8 '07 #6

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

Similar topics

4
by: Timothy Fitz | last post by:
Why are all numberical literals in exponential notation floats? To me it is counter-intuitive for 1e3 to behave so fundamentally different from 1000. Timothy Fitz
1
by: Mahesha | last post by:
Exponential Moving avg is calculated using the formula. EMA = (Today's Price)* K + (EMA yesterday) * (1-K) where K = 2 / (N+1) The user is going to Input the K. It is something like F(N) =...
1
by: diegoandrade | last post by:
In this code the exponential part using scientific notation becomes e+002 is ther a way of changging the number of values after e so they can appear like e+02, only 2 values instead 3?? I have...
9
by: J.Sperlhofer | last post by:
Good morning, Javascript-Professionals. I'm looking for an possibility to show a (calculated) 64bit-Number without exponential notation. I don't want to see exponational notation within my...
2
by: Rod Brick | last post by:
I'm trying to print a Double in straight decimal form, not exponential. I can't seem to accomplish this. This seems like it should be simple enough. The output I'm looking for is "0.00001", not...
8
by: Martin Jørgensen | last post by:
Hi, I have a program that reads in a couple of numbers from files and then stores them with some latex-code but I'm not satisfied with the exponential output, as it takes up too many character...
2
by: Poz | last post by:
Is there a way to convert an exponential number (held in string format) to non-exponential format without losing any precision in the number? For example, I have a string variable containing...
4
by: b4ukiran | last post by:
Hi all, I have a requirement to print large double values without the exponential notaion. The double value can be a declared variable or any calculated value within the code. In any case, I...
8
by: pereges | last post by:
Hi, can anyone please tell me what is wrong in this program and why does it keep givng nan as the output(eg. take input as 1.2e+10) ? #include <stdio.h> #define PLANCK 6.626068e10-34 int...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

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.