Does anyone know if it is possible to represent a number as a string with
engineering notation (like scientific notation, but with 10 raised to
multiples of 3: 120e3, 12e-6, etc.). I know this is possible with the
decimal.Decimal class, but repeatedly instantiating Decimals is inefficient
for my application (matplotlib plotting library). If it is not currently
possible, do you think the python devs would be receptive to including
support for engineering notation in future releases?
Thanks,
Darren 6 6635
Darren Dale wrote:
Does anyone know if it is possible to represent a number as a string with
engineering notation (like scientific notation, but with 10 raised to
multiples of 3: 120e3, 12e-6, etc.). I know this is possible with the
decimal.Decimal class, but repeatedly instantiating Decimals is inefficient
for my application (matplotlib plotting library). If it is not currently
possible, do you think the python devs would be receptive to including
support for engineering notation in future releases?
How close is this:
>>"%.3e" % 3.14159
'3.142e+00'
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
Blog of Note: http://holdenweb.blogspot.com
See you at PyCon? http://us.pycon.org/TX2007
Steve Holden wrote:
Darren Dale wrote:
>Does anyone know if it is possible to represent a number as a string with engineering notation (like scientific notation, but with 10 raised to multiples of 3: 120e3, 12e-6, etc.). I know this is possible with the decimal.Decimal class, but repeatedly instantiating Decimals is inefficient for my application (matplotlib plotting library). If it is not currently possible, do you think the python devs would be receptive to including support for engineering notation in future releases?
How close is this:
>>"%.3e" % 3.14159
'3.142e+00'
>>"%.3e" % 31415.9
'3.142e+04'
What I am looking for is '31.4159e+03'
Darren
On 2007-03-14, Steve Holden <st***@holdenweb.comwrote:
Darren Dale wrote:
>Does anyone know if it is possible to represent a number as a string with engineering notation (like scientific notation, but with 10 raised to multiples of 3: 120e3, 12e-6, etc.). I know this is possible with the decimal.Decimal class, but repeatedly instantiating Decimals is inefficient for my application (matplotlib plotting library). If it is not currently possible, do you think the python devs would be receptive to including support for engineering notation in future releases?
How close is this:
>>"%.3e" % 3.14159
'3.142e+00'
Not close at all. It should be "3.14159"
>>"%.3e" % 31.4159
'3.142e+01'
should be 31.4159
>>"%.3e" % 314.159
'3.142e+02'
should be 314.159
>>"%.3e" % 31415.9
'3.142e+04'
should be 31.4159e3
--
Grant Edwards grante Yow! LOU GRANT froze
at my ASSETS!!
visi.com
Steve Holden <st***@holdenweb.comwrites:
Darren Dale wrote:
>Does anyone know if it is possible to represent a number as a string with engineering notation (like scientific notation, but with 10 raised to multiples of 3: 120e3, 12e-6, etc.). I know this is possible with the decimal.Decimal class, but repeatedly instantiating Decimals is inefficient for my application (matplotlib plotting library). If it is not currently possible, do you think the python devs would be receptive to including support for engineering notation in future releases?
How close is this:
>>"%.3e" % 3.14159
'3.142e+00'
>>"%.3e" % 314159
'3.142e+05'
>>>
Not close when you have the exponent.
--
Jorge Godoy <jg****@gmail.com>
On Mar 14, 1:14 pm, Darren Dale <d...@cornell.eduwrote:
Does anyone know if it is possible to represent a number as a string with
engineering notation (like scientific notation, but with 10 raised to
multiples of 3: 120e3, 12e-6, etc.). I know this is possible with the
decimal.Decimal class, but repeatedly instantiating Decimals is inefficient
for my application (matplotlib plotting library). If it is not currently
possible, do you think the python devs would be receptive to including
support for engineering notation in future releases?
Do you also consider this to be too inefficient?
import math
for exponent in xrange(-10, 11):
flt = 1.23 * math.pow(10, exponent)
l = math.log10(flt)
if l < 0:
l = l - 3
p3 = int(l / 3) * 3
multiplier = flt / pow(10, p3)
print '%e =%fe%d' % (flt, multiplier, p3)
--
Hope this helps,
Steven at*************@gmail.com wrote:
On Mar 14, 1:14 pm, Darren Dale <d...@cornell.eduwrote:
>Does anyone know if it is possible to represent a number as a string with engineering notation (like scientific notation, but with 10 raised to multiples of 3: 120e3, 12e-6, etc.). I know this is possible with the decimal.Decimal class, but repeatedly instantiating Decimals is inefficient for my application (matplotlib plotting library). If it is not currently possible, do you think the python devs would be receptive to including support for engineering notation in future releases?
Do you also consider this to be too inefficient?
import math
for exponent in xrange(-10, 11):
flt = 1.23 * math.pow(10, exponent)
l = math.log10(flt)
if l < 0:
l = l - 3
p3 = int(l / 3) * 3
multiplier = flt / pow(10, p3)
print '%e =%fe%d' % (flt, multiplier, p3)
That's a good suggestion. It's probably fast enough. I was hoping that
something like '%n'%my_number already existed. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: LRW |
last post by:
OK, this is probably an odd, but esy question. =)
I taught myself PHP from a Julie Meloni book and newsgroup questions.
So, I don't think I've really learned the proper way of organizing and...
|
by: David Sharp |
last post by:
I'm trying to find a way to format a FLOAT variable into a varchar in
SQL Server 2000 but using CAST/CONVERT I can only get scientific
notation i.e. 1e+006 instead of 1000000 which isn't really...
|
by: Steve Johnson |
last post by:
I'd like to hear thoughts on what books, in your opinion, are true
classics in the field of software engineering. I read a lot on the
topic - at least a book a month for many years. There are many...
|
by: CJ |
last post by:
This is a really silly question, but I just can't get it right.
I have a double; the value is 0.00003025. I want to display it exactly
as it stands, but by default it is displayed in scientific...
|
by: John Salerno |
last post by:
My initial feeling is that concatenation might take longer than
substitution, but that it is also easier to read:
def p(self, paragraph):
self.source += '<p>' + paragraph + '</p>\n\n'
vs.
...
|
by: OriginalBrownster |
last post by:
Hi there:
I was wondering if its at all possible to search through a string for a
specific character.
I want to search through a string backwords and find the last
period/comma, then take...
|
by: Scewbedew |
last post by:
Suppose I have the following code:
string myFormat = "Line1/nLine 2";
string formattedString = string.Format(myFormat);
....that would produce a 2-line output as expected.
But if I load...
|
by: mary |
last post by:
Hi, for my thesis at the university I'm working on a Visual c++ 6.0
source code, to understand better it I need to extract the UML
graphics: Class Diagram, Object Diagram, Use Case Diagram, State...
|
by: FAQ server |
last post by:
-----------------------------------------------------------------------
FAQ Topic - How do I access a property of an object using a string?...
|
by: MeoLessi9 |
last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
|
by: Aftab Ahmad |
last post by:
Hello Experts!
I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
|
by: Aftab Ahmad |
last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below.
Dim IE As Object
Set IE =...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: marcoviolo |
last post by:
Dear all,
I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
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...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
| |