【问题标题】:how to convert fstring variable to 2 decimal places in python? [duplicate]如何在python中将fstring变量转换为2位小数? [复制]
【发布时间】:2022-07-30 18:18:38
【问题描述】:

如何打印:

print(f"\nTotal amount inserted: ${total_money}")

所以总金额将显示到小数点后 2 位?

【问题讨论】:

    标签: python


    【解决方案1】:

    您应该在{num:.Nf} 中使用N 指定小数位数。 例如:

    >>> print(f'{2:.2f}')
    2.00
    

    【讨论】:

      猜你喜欢
      • 2021-01-26
      • 1970-01-01
      • 2019-01-20
      • 1970-01-01
      • 2012-04-10
      • 2018-06-02
      • 2017-10-13
      • 1970-01-01
      • 2023-03-11
      相关资源
      最近更新 更多