Print number in engineering format

前端 未结 6 1713
陌清茗
陌清茗 2020-12-06 01:22

I am trying to print a number into engineering format with python, but I cannot seem to get it to work. The syntax SEEMS simple enough, but it just doesn\'t work.



        
6条回答
  •  [愿得一人]
    2020-12-06 02:10

    It is 2020 now folks! and there is an COVID-19 pandemic. You got to use f-string literals for this type of work:

    With python3.6.4 and above, you can do

    a = 3e-4
    print(f"{a:.0E}")
    

提交回复
热议问题