如何将整数转换为逗号分隔的字符串 [英] How to convert an integer to a comma separated string

查看:104
本文介绍了如何将整数转换为逗号分隔的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发程序,但是遇到了问题.

I'm currently working on a program and I've run into a problem.

我的银行存款余额为1000000,但当我在屏幕上显示时,我希望其显示为"1000000".

I have a bank balance of 1000000 but when I display it on the screen I want it to read as "1,000,000".

现在,有多种方法可以解决此问题,方法是将其设置为"1,000,000",然后将其去除逗号并在需要使用整数值时将其转换为整数.但是我不想那样做.

Now there are ways of getting around this simply by having it set to "1,000,000" and then striping it of commas and converting it to an integer when I need to use the integer value. But I don't want to do that.

bankBalance = 1000000

推荐答案

使用 format :

>>> bankBalance = 1000000
>>> format(bankBalance, ",")
'1,000,000'
>>>

这篇关于如何将整数转换为逗号分隔的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆