Add zeros to a float after the decimal point in Python

前端 未结 4 712
感动是毒
感动是毒 2020-12-01 03:26

I am reading in data from a file, modify it and write it to another file. The new file will be read by another program and therefore it is crucial to carry over the exact fo

4条回答
  •  隐瞒了意图╮
    2020-12-01 04:24

    From Python 3.6 it's also possible to do f-string formatting. This looks like:

    f"{value:.6f}"
    

    Example:

    > print(f"{2.0:.6f}")
    '2.000000'
    

提交回复
热议问题