On Thu, Oct 21, 2010 at 14:21, Sander Sweers <sander.swe...@gmail.com> wrote: > On 21 October 2010 18:09, Richard D. Moores <rdmoo...@gmail.com> wrote:
>> I'd appreciate constructive criticism. > > Instead of all the zeros2float craziness use string formatting. It > will take care of rounding and the number of decimal places. > >>>> import datetime >>>> lowz = 81.7499997345 >>>> timestamp = datetime.datetime.now().strftime("%H:%M:%S") >>>> print "NEW LOW: %.4f at %s" % (lowz, timestamp) > NEW LOW: 81.7500 at 22:55:13 > > If you want to control the number of decimal places in the string > formatting do something like: > >>>> i = 3 >>>> print ("NEW LOW: %%.%sf at %%s" % i) % (lowz, timestamp) > NEW LOW: 81.750 at 22:55:13 >>>> i = 6 >>>> print ("NEW LOW: %%.%sf at %%s" % i) % (lowz, timestamp) > NEW LOW: 81.750000 at 22:55:13 Thanks very much for the string formatting instruction. Dick _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor