On 06/28/2010 09:38 AM, Dean Allen Provins, P. Geoph. wrote: > Tom: > > On Mon, Jun 28, 2010 at 04:05:20AM -0400, Tom Bell wrote: > >> Dean, >> Yes, I would like a copy of your code snippet, if only to see >> what it is doing. I find it hard to believe there is no way to >> implement this using Decimal or "to_eng_string". They >> appear to have been written to address this very thing. >> Thank you! >> >> Tom >> > You will have to write an appropriate python macro for Calc, of > course, and I cannot assist with that, but the code (following) > may be of use to you. > > --------------------- eng.py ------------------ > # eng.py > # > > def eng (F = 0, fmt = "%fe%d"): > f = abs (F) > n = 0 > s = +1 > if F < 0: > s = -1 > > if f != 0: > if f >= 1.: > while (f >= 1.): > f /= 10. > n += 1 > > f *= 10. > n -= 1 > > while (n % 3): > n += 1 > f /= 10. > else: > while (f < 1.): > f *= 10. > n -= 1 > > while (n % 3): > n += 1 > f /= 10. > > # Uncomment these if you want a leading '0.' > #f /= 10. > #n += 1 > > S = fmt % (s * f, n) # store this result in a cell > > print "F (%g) = %s" % (F, S) # delete this in the macro > > # ---------end of the function --------- > # Some tests... Try them by running "python eng.py" > > eng () > print > > eng (1.) > eng (1.23) > eng (123) > eng (1234.567) > print > > eng (-1.) > eng (-1.23) > eng (-123) > eng (-1234.567) > print > > eng (11.) > print > > eng (0.4) > eng (-0.4) > print > > eng (0.004) > eng (-0.04) > print > > eng (0.001234567E-7) > eng (-0.001234567E-7) > ---------------------------------------------- > > Dean > > I am replying on the list and personally. If you could send me the file, maybe I can run it. As it is I cannot seem to get it to run with a response. When I create the file "eng.py" and type python eng.py at the prompt, all I get is a prompt back with no other information, good, bad or indifferent. I cannot seem to run it from within python either, if that is possible. I may be creating the file incorrectly, however, python does not give any error response. It is either my python setup or file creation that is the failure point. Thank you!
Tom -- "PC, "Where would you like to go today?" ... Mac, "Where would you like to be tomorrow?" ... Linux, "Are you guys coming, or not?""
