How to format a floating number to fixed width in Python

后端 未结 8 1093
长发绾君心
长发绾君心 2020-11-22 10:26

How do I format a floating number to a fixed width with the following requirements:

  1. Leading zero if n < 1
  2. Add trailing decimal zero(s) to fill up f
8条回答
  •  一向
    一向 (楼主)
    2020-11-22 11:06

    I needed something similar for arrays. That helped me

    some_array_rounded=np.around(some_array, 5)
    

提交回复
热议问题