number of displayed decimal places

Fernando Pérez fperez528 at yahoo.com
Wed May 15 13:08:51 EDT 2002


Vojin Jovanovic wrote:

> I would like to know if one can control the number of displayed decimal
> places in Python similarly to what one can do in MATLAB
> 
[snip]
> 
> Now, I know that Python can control the outputs with print  %f  and so on
> ...  but it would be more useful if one can somehow set the number of
> displayed decimal places in the beginning.

Well, you may want to look at IPython: 
http://www-hep.colorado.edu/~fperez/ipython/

Among other things, it has pre-made profiles for turning it into a matlab-like 
environment, loading numeric and gnuplot controllers for you. And I've 
already coded in the hooks for controlling the formatting of numerical 
output, but only the necessary hooks are in place. I have yet to write the 
actual format code. For simple numbers it would be trivial, the tricky part 
is nice formatting of multi-dimensional matrices.

But you could at least in a few minutes fix the display of floats, and if you 
want to take a shot at matrix formatting I'll be glad to include any 
contributions in future releases.

Cheers,

f.



More information about the Python-list mailing list