在Python中将整数格式化为GBP

2024-09-29 19:27:10 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直在尝试将一定数量的信用卡格式化为英镑,例如将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 

Tags: format密码数量信用卡thisoutputsprintplayercredit
2条回答

您可以简单地使用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')]))

相关问题 更多 >

    热门问题