【问题标题】:how to get 4 digits after decimal with floor to the amount?如何获得金额下限的小数点后4位?
【发布时间】:2022-07-12 01:34:53
【问题描述】:

我想取一个价格并将其除以 3,但我不能让结果的总和大于价格,即

price = 0.6096689733333334
four_digits = '{:.{}f}'.format(float(price), 4)

返回 0.6097

有没有办法让“four_digits”的结果为 0.6096 ? (又名最后一位数字被击倒)

提前感谢任何帮助者!

【问题讨论】:

    标签: python finance binance


    【解决方案1】:

    使用math

    import math
    
    price = 0.6096689733333334
    four_digits = math.floor(price * 10000)/10000
    print(f"{four_digits}")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-24
      • 2011-04-22
      相关资源
      最近更新 更多