2024-09-29 19:27:10 发布
网友
我一直在尝试将一定数量的信用卡格式化为英镑,例如将100个信用卡显示为1.00英镑,将80个信用卡显示为0.80英镑。我正在运行python3.5。你知道吗
这是我的密码:
playerCredit = 100 print(format(playerCredit, ',.2f')) #this outputs 100.00 playerCredit = 80 print(format(playerCredit, ',.2f')) #this outputs 80.00
您可以简单地使用format函数来打印所需的结果。你知道吗
示例代码如下:
x=1 print('£' + format(x/100. ,',.2f'))
希望这有帮助。你知道吗
这样行吗?你知道吗
playerCredit = 100 print(format(playerCredit/100., ',.2f')) playerCredit = 80 print(format(playerCredit/100., ',.2f'))
如果您想添加符号,那么应该在python3.x中执行以下操作(在2.x中,您需要对符号进行编码)
print(''.join(['£', format(playerCredit/100., ',.2f')]))
您可以简单地使用format函数来打印所需的结果。你知道吗
示例代码如下:
希望这有帮助。你知道吗
这样行吗?你知道吗
如果您想添加符号,那么应该在python3.x中执行以下操作(在2.x中,您需要对符号进行编码)
相关问题 更多 >
编程相关推荐