Python precision in string formatting with float numbers

Viewed 32176

I don't understand why, by formatting a string containing a float value, the precision of this last one is not respected. Ie:

'%f' % 38.2551994324

returns:

'38.255199'

(4 signs lost!)

At the moment I solved specifying:

'%.10f' % 38.2551994324

which returns '38.2551994324' as expected… but should I really force manually how many decimal numbers I want? Is there a way to simply tell to python to keep all of them?! (what should I do for example if I don't know how many decimals my number has?)

2 Answers
Related