#!/usr/bin/env python
# -*- # coding:gbk
def intcomma(value):
orig = str(value)
new = re.sub("^(-?\d+)(\d{3})", '\g<1>,\g<2>', orig)
if orig == new:
return new
else:
return intcomma(new)
if __name__ == '__main__':
print '==start=='
print intcomma(4500)
print intcomma(10000000000)
print intcomma(5464561.55)
print '==end=='
---------- python ----------
==start==
4,500
10,000,000,000
5,464,561.55
==end==
Output completed (0 sec consumed) - Normal Termination
只是简化了Django下contrib.humanize.templatetags.humanize.py里面的一段源码。没事看看源码还是挺好的