对编码和 Python 非常陌生。我试图将计算结果限制为小数点后两位,或者我想要的任意位数。通过 Google 发现了有关使用小数的信息,但我无法让我的代码正常工作。
我从什么开始
amount_per_day = amount_of_money/currency_amount
print("If you are going to spend " + str(amount_of_money) + " " + str(destination_currency) + " that means that you can spend up to " + str(amount_per_day) + " " + Home_currency + " per day to remain in budget.")
我尝试过的
from decimal import Decimal
amount_per_day = Decimal(amount_of_money/currency_amount)
amount_per_day_to_two_decimal_places = round(amount_per_day,2)
print("If you are going to spend " + str(amount_of_money) + " " + str(destination_currency) + " that means that you can spend up to " + str(amount_per_day) + " " + Home_currency + " per day to remain in budget.")
结果
如果您打算花费 2000.0 欧元,这意味着您每天最多可以花费 1818.181818181818016455508768558502197265625 英镑以保持在预算之内。
这些代码可以工作,但我不需要小数点后 39 位的答案。
倚天杖
侃侃尔雅
达令说
富国沪深
相关分类