Number of digits in exponent

后端 未结 4 1734
忘了有多久
忘了有多久 2020-12-01 14:30

Is it possible to set the number of digits to be used for printing the exponent of a floating-point number? I want to set it to 3.

Currently,

f = 0.0         


        
4条回答
  •  猫巷女王i
    2020-12-01 14:37

    You can use np.format_float_scientific

    from numpy import format_float_scientific
    
    f = 0.0000870927939438012
    
    format_float_scientific(f, exp_digits=3) # prints '8.70927939438012e-005'
    
    format_float_scientific(f, exp_digits=5, precision=2) #prints '8.71e-00005'
    

提交回复
热议问题