How to suppress scientific notation when printing float values?

后端 未结 12 1387
猫巷女王i
猫巷女王i 2020-11-22 07:12

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

12条回答
  •  没有蜡笔的小新
    2020-11-22 07:37

    Most of the answers above require you to specify precision. But what if you want to display floats like this, with no unnecessary zeros:

    1
    0.1
    0.01
    0.001
    0.0001
    0.00001
    0.000001
    0.000000000001
    

    numpy has an answer: np.format_float_positional

    import numpy as np
    
    def format_float(num):
        return np.format_float_positional(num, trim='-')
    

提交回复
热议问题