Tom:

On Thu, May 27, 2010 at 09:31:24PM -0400, Tom Bell wrote:
> Can someone familiar with Python programming
> explain whether or not the code snippet at:
> http://coding.derkeiler.com/Archive/Python/comp.lang.python/2007-03/msg01958.html
> works in a Python macro for OOo Calc???
> Thank you!
> 
> Tom

I cannot answer your question re OO macros, but after examining
the code snippet, I might suggest a quicker way to get what you
are after.  I believe that this should work in your macro:

------------------engineering notation function --------------
def eng (F = 0):
 f = abs (F)
 n = 0
 s = +1
 if F < 0:
  s = -1

 if f != 0:
   while (f >= 1.):
    f /= 10.
    n += 1

   f *= 10.
   n -= 1

 S = "%fe%d" % (s * f, n)       # insert this result in a cell

 print "F (%f) = %s" % (F, S)   # delete this from your macro

----------------------function end, tests follow -----------------

print "Some tests:"

eng ()

eng (1.)
eng (1.23)
eng (123)

eng (-1.)
eng (-1.23)
eng (-123)

eng (11.)
eng (0.4)
eng (-0.4)

Dean

-- 
                           Dean Provins, P. Geoph.
                         [email protected]
                  KeyID at at pgpkeys.mit.edu:11371: 0x9643AE65
          Fingerprint: 9B79 75FB 5C2B 22D0 6C8C 5A87 D579 9BE5 9643 AE65

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to