float to string with different precision

zunbeltz at gmail.com zunbeltz at gmail.com
Fri Aug 10 09:40:17 CEST 2007


Hi,

I have to print float numbers to a file. Each float should be 5
characters in width (4 numbers and the decimal point).
My problem is that I do not now how to specify float to have different
numbers of decimals. For example

5.32 -> 5.320
10.356634 -> 10.357
289.234 -> 289.2

In the string formating operations only fixed number of decimal digits
is allow.

Thanks in advance for the help,

Zunbeltz




More information about the Python-list mailing list