<分区> 分区>
我试图将数字的输出限制为 4 个字符(包括小数)。
def costEdit(nCost):
nCost = '%.2f'%(nCost*1.25)
nCost = nCost * 1.25
return nCost
我希望 nCost 在小数点后 2 位截断。例如。如果 nCost 为 8.364912734,则将其截断为 8.36 并编辑 nCost 变量以将其替换。有什么想法吗?
我收到错误:
Traceback (most recent call last):
File "C:\Python33\My Codes\TextTowns\TextTowns.py", line 59, in <module>
costEdit(nCost)
File "C:\Python33\My Codes\TextTowns\TextTowns.py", line 27, in costEdit
nCost = nCost*1.25
TypeError: can't multiply sequence by non-int of type 'float'
我将其用作:costEdit(nCost)
