[Tutor] How to print numbers in scientific notation form?

Dick Moores rdm at rcblue.com
Sat Jun 28 14:55:04 CEST 2008


%.4g comes close to what I want, but no cigar. In the examples below, 
the first 2 are not scientific notation form.

 >>> print "%.4g" % 5.09879870978
5.099
 >>> print "%.4g" % .0009874345
0.0009874
 >>> print "%.4g" % .000009878
9.878e-006
 >>> print "%.4g" % 187686876876238746
1.877e+017

How can I print all numbers in scientific notation form, and 
designate the number of significant digits?

Thanks,

Dick Moores



More information about the Tutor mailing list