如何计算销售百分比

0 投票
3 回答
1169 浏览
提问于 2025-04-19 03:44
print("Profit Predition.")

sales=input("Enter amount of sales: ")

print('Total sales: ', sales)

profit=sales* 0.21

print(format(profit, ',.2'))

我在最后一行得到的结果应该是(使用的输入是 974.58,这只是一个示例):

Profit Prediction.
Enter amount of sales: 974.58
Total sales: 974.58
Expected profit: 204.66

但是我得到的最后一行却是 2e+02。我不知道怎么才能让它返回一个“浮点数”。我对编程还很陌生,希望能得到帮助!我使用的Python版本是3.3.5

3 个回答

0

试试看

print("{:,.2f}".format(profit))

想了解更多细节,请参考 这个链接

1

我总是这样使用 print

print("%.2f" % profit)
2

更新:我很抱歉之前的错误。我已经更新了我的回答。

所以试着把最后一行换成:

print('%.2f' % profit)

或者

print("{0:.2f}".format(profit))

这样你就能得到正确的结果了。

撰写回答