>>> "{:,}".format(56381779049) '56,381,779,049' >>> "{:,}".format(56381779049.1) '56,381,779,049.1' >>>
>>> import re >>> subject = '1234567' >>> result = re.sub(r"(?<=\d)(?=(?:\d\d\d)+$)", ",", subject) >>> result '1,234,567'
>>> import re >>> subject = '1234567' >>> result = re.sub(r"(\d)(?=(\d\d\d)+(?!\d))", r"\1,", subject) >>> result '1,234,567'
Python 2.7 (r27:82500, Nov 23 2010, 18:07:12) [GCC 4.1.2 20070115 (prerelease) (SUSE Linux)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> format(1234567890,',') '1,234,567,890' >>>
import re def strConv(s): s = str(s) while True: (s,count) = re.subn(r"(\d)(\d{3})((:?,\d\d\d)*)$",r"\1,\2\3",s) if count == 0 : break return s print strConv(12345)
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
长按识别二维码并关注微信
更方便到期提醒、手机管理