yourtion / alfred_numtocny Goto Github PK
View Code? Open in Web Editor NEW转换数字为人民币金额的Alfred Workflow
Home Page: http://www.packal.org/workflow/numtocny
转换数字为人民币金额的Alfred Workflow
Home Page: http://www.packal.org/workflow/numtocny
使用时发现有点问题,修正了下。
一是在万圆时没有圆字;
二是在万亿时有错误;
``` python````
import math
def numtoCny(num):
capUnit = ['万','亿','万','圆','']
capDigit = { 2:['角','分',''], 4:['仟','佰','拾','']}
capNum=['零','壹','贰','叁','肆','伍','陆','柒','捌','玖']
snum = str('%019.02f') % num
if snum.index('.')>16:
return '输入数据过长'
ret,nodeNum,subret,subChr='','','',''
CurChr=['','']
for i in range(5):
j=int(i*4+math.floor(i/4))
subret=''
nodeNum=snum[j:j+4]
lens=len(nodeNum)
for k in range(lens):
if int(nodeNum[k:])==0:
continue
CurChr[k%2] = capNum[int(nodeNum[k:k+1])]
if nodeNum[k:k+1] != '0':
CurChr[k%2] += capDigit[lens][k]
if not ((CurChr[0]==CurChr[1]) and (CurChr[0]==capNum[0])):
if not((CurChr[k%2] == capNum[0]) and (subret=='') and (ret=='')):
subret += CurChr[k%2]
subChr = [subret,subret+capUnit[i]][subret!='']
if not ((subChr == capNum[0]) and (ret=='')):
ret += subChr
####万亿时没有亿字
if len(str(int(num)))>12 and len(str(int(num)))-j<13 and (capUnit[1] not in ret):
ret += capUnit[1]
####万圆时没有圆字
if ret and (not ret.endswith(capUnit[3])):
ret+=capUnit[3]
return [ret,capNum[0]+capUnit[3]][ret=='']
def callback(strs):
print('')
print('')
print(" <item uid="octal" valid="yes" arg=""+strs+"">")
print(" <title>"+strs+"</title>")
print(' Copy to clipboard')
print(' icon.png')
print(' ')
print('')
callback(numtoCny({query}))
I think your code in source.py has a little problem. Maybe the "arg" of "res" should be ret
使用这个会有问题。
cny 10000,0000,1234
壹万亿壹仟贰佰叁拾肆圆整
#处理万亿以上的部分
if integer_part >= 1000000000000 and wanyi_part > 0:
zero_count = _parse_integer(strio, wanyi_part, zero_count, True)
if yi_part > 0:
strio.write('万')
else:
strio.write('万亿')
结尾多了一个圆字
最后应该是贰分,不是壹分
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.