How to suppress scientific notation when printing float values?
'%f' % (x/y)
but you need to manage precision yourself. e.g.,
'%f' % (1/10**8)
will display zeros only.
details are in the docs
Or for Python 3 the equivalent old formatting or the newer style formatting
Using the newer version ''.format
(also remember to specify how many digit after the .
you wish to display, this depends on how small is the floating number). See this example:
>>> a = -7.1855143557448603e-17
>>> '{:f}'.format(a)
'-0.000000'
as shown above, default is 6 digits! This is not helpful for our case example, so instead we could use something like this:
>>> '{:.20f}'.format(a)
'-0.00000000000000007186'
Update
Starting in Python 3.6, this can be simplified with the new formatted string literal, as follows:
>>> f'{a:.20f}'
'-0.00000000000000007186'
With newer versions of Python (2.6 and later), you can use ''.format()
to accomplish what @SilentGhost suggested:
'{0:f}'.format(x/y)