How can I reduce the number of digits after decimal point when writing floats to file?

python

Solution

You can use basic string formatting, such as:

>>> print '%.4f' % (2.2352341234)
2.2352

Here, the `%.4f` tells Python to limit the precision to four decimal places.

Problem

In my program I am printing float numbers to file. There is high precision of these numbers so there are many digits after decimal point, i.e number 0.0433896882981. How can I reduce number of digits that I print into file? So I would print, say, 0.043 instead of 0.0433896882981.

Original source