Here's my code:
x = 1.0 y = 100000.0 print x/y My quotient displays as 1.00000e-05.
Is there any way to suppress scientific notation and make it display as 0.00001? I'm going to use the result as a string.
Within a given f-string, you can use the {...:f} format specifier to tell Python to use floating point notation for the number preceding the :f suffix. Thus, to print the number my_float = 0.00001 non-scientifically, use the expression print(f'{my_float:f}') .
`e' This prints a number in scientific (exponential) notation. For example, printf "%4.3e", 1950 prints `1.950e+03', with a total of four significant figures of which three follow the decimal point. The `4.3' are modifiers, discussed below. `f' This prints a number in floating point notation.
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' Starting in Python 3.6, this can be simplified with the new formatted string literal, as follows:
>>> f'{a:.20f}' '-0.00000000000000007186'
'%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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With