I can run the attached file in a konsole, python eng.py However, I need to put it into an add-on form. Can you tell me where I can get information that will me to incorporate this into Calc so I and others can use Engineering Notation. All powers divided by three is what is needed and this code snippet does that. I tried decimal and to_eng_string that is located in decimal according to the Python coding page, but it doesn't seem to work. Engineers and engineering students do need Engineering Notation and right now, only Excel allows it, Calc does not. One way or another I intend to get this done for all the engineers and students who need it. 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?""
# eng.py # def eng (F = 0, fmt = "%fe%d"): """ Formats a floating point number (F) according to the format provided (fmt). Tries to use engineering notation (i.e. the exponent is in powers of three). Dean Provins, June, 2010 """ 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 return fmt % (s * f, n) # return the formatted string to store in a cell # ---------end of the function --------- if __name__ == "__main__": # Some tests... Try them by running "python eng.py" print "some tests" print "----------" print "0:", eng () print print "1.:", eng (1.) print "1.23:", eng (1.23) print "123:", eng (123) print "1234.567:", eng (1234.567) print print "-1:", eng (-1.) print "-1.23:", eng (-1.23) print "-123:", eng (-123) print "-1234.567:", eng (-1234.567) print print "11.:", eng (11.) print print "0.4:", eng (0.4) print "-0.4:", eng (-0.4) print print "0.004:", eng (0.004) print "0.04:", eng (-0.04) print print "0.001234567E-7:", eng (0.001234567E-7) print "-0.001234567E-7:", eng (-0.001234567E-7)
--------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@api.openoffice.org For additional commands, e-mail: dev-h...@api.openoffice.org