Hi,
Sorry, my answer above makes them both have 10 decimal places...
if you want exactly 10 characters in the output, you need to change the decimal places to account for whole number size, as well as negative numbers...
This can be done with a slightly different format string, e.g.
>>> print '%10f' % float1
-0.037468
>>> print '%10f' % float2
0.000001
>>> len( '%10f' % float1 )
10
>>> len ( '%10f' % float2 )
10
Main Topics
Browse All Topics





by: cjjcliffordPosted on 2005-06-20 at 03:00:25ID: 14255302
>>> print '%.10f' % float1
-0.0374676511
>>> print '%.10f' % float2
0.0000007719
>>>
And to a file (assuming variable filename)
out = file( filename, 'w' )
out.write( '%.10f\n' % float1 )
out.write( '%.10f\n' % float2 )
out.close()