python 大数字添加千分符
2013-06-20 20:59
176 查看
def NumberToStr(num, flag=True): try: if flag: num = int(num) else: num = float(num) except: return num if(type(float(1.1))==type(num)): str_num="%.2f"%num elif (type(int(1))==type(num)): str_num=str(num) else: return num left_len=length=len(str_num) right_len=0 dot_cnt=str_num.count('.',0,length) if(dot_cnt!=0):#小数 left_len=str_num.index('.',0,length) right_len=length-left_len cnt=left_len//3 result=[] end=left_len while(cnt>0): result.append(str_num[end-3:end]) end-=3 cnt-=1 result.append(str_num[:end]) result.reverse() result_str=','.join(result) result_str+=str_num[left_len:] if(result_str[0]==','): return result_str[1:] else: return result_str
相关文章推荐
- Python练手项目0 - 给头像右上角添加数字
- Python每日练习 01 图像右上角添加数字
- Python数字加千分符
- python为每三位数字添加点标记
- Python 正则表达式添加数字千位分隔符
- python 图片右上角添加数字源代码
- Python 练习册 0-头像右上角添加数字
- [python每日一练]--0000:图片添加数字
- python 在图片添加数字,初学者容易出现的报错及解决办法
- python 在图片右上角添加红色数字
- 【python PIL】数字水印添加以及检测
- 【涉及到python的小项目:openCV人脸识别(一)】在csv文件中的每一行信息后面添加数字标签
- 处理表单输入数字自动添加千分符
- python 图片上添加数字源代码
- javascript为数字添加千分符
- Python 练习册 0-头像右上角添加数字
- python学习——修改、添加和删除元素
- python判断数字是否是超级素数幂
- python中List添加元素的几种方法
- python添加module问题解决no module named XXX