首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

人民币金额数目字转中文大写

2012-10-07 
人民币金额数字转中文大写看到一个帖子,人民币金额数字转中文大写,无聊也用PHP写了一段相同功能的代码:htt

人民币金额数字转中文大写
看到一个帖子,
人民币金额数字转中文大写,无聊也用PHP写了一段相同功能的代码:


http://www.jamcode.org/

相同的JS代码
from operator import addfrom itertools import cycle,groupbyunits=cycle(["拾","佰","仟","万","拾","佰","仟","亿"])nums=["零","壹","贰","叁","肆","伍","陆","柒","捌","玖"]splitUnit=["万","亿"]sjoin="".joindef cny(ns):  a=zip(ns[::-1][1:],units)  a=reduce(add,[list(v) if i!='0' else reduce(tozero,list(v),[]) for i,v in groupby(a,lambda t:t[0])])  return sjoin(map(lambda t:"%s%s"%(t[0] and nums[int(t[0])],t[1]),a[::-1]+[(ns[-1],'')]))def tozero(acc,t):  if t[1] in splitUnit:    acc.append(('',t[1]))  elif len(acc)==0:    acc.append(('0',''))  return acc




1 楼 mikixiyou 2012-07-27   坦白说,这种实现方法确实是前端应用中应该去实现的。

热点排行