博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
银行钱数(带小数位)转大写
阅读量:4101 次
发布时间:2019-05-25

本文共 1746 字,大约阅读时间需要 5 分钟。

 摘自:

# 钱数转大写def convertNumToChinese(totalPrice):    dictChinese = [u'零',u'壹',u'贰',u'叁',u'肆',u'伍',u'陆',u'柒',u'捌',u'玖']    unitChinese = [u'',u'拾',u'佰',u'仟','',u'拾',u'佰',u'仟']    #将整数部分和小数部分区分开    partA = int(math.floor(totalPrice))    partB = round(totalPrice-partA, 2)    strPartA = str(partA)    strPartB = ''    if partB != 0:        strPartB = str(partB)[2:]    singleNum = []    if len(strPartA) != 0:        i = 0        while i < len(strPartA):            singleNum.append(strPartA[i])            i = i+1    #将整数部分先压再出,因为可以从后向前处理,好判断位数    tnumChinesePartA = []    numChinesePartA = []    j = 0    bef = '0';    if len(strPartA) != 0:        while j < len(strPartA) :            curr = singleNum.pop()            if curr == '0' and bef !='0':                tnumChinesePartA.append(dictChinese[0])                bef = curr            if curr != '0':                tnumChinesePartA.append(unitChinese[j])                tnumChinesePartA.append(dictChinese[int(curr)])                bef = curr            if j == 3:                tnumChinesePartA.append(u'萬')                bef = '0'            j = j+1        for i in range(len(tnumChinesePartA)):            numChinesePartA.append(tnumChinesePartA.pop())    A = ''    for i in numChinesePartA:        A = A+i    #小数部分很简单,只要判断下角是否为零    B = ''    if len(strPartB) == 1:        B = dictChinese[int(strPartB[0])] + u'角'    if len(strPartB) == 2 and strPartB[0] != '0':        B = dictChinese[int(strPartB[0])] + u'角' + dictChinese[int(strPartB[1])] + u'分'    if len(strPartB) == 2 and strPartB[0] == '0':        B = dictChinese[int(strPartB[0])] + dictChinese[int(strPartB[1])] + u'分'    if len(strPartB) == 0:        S = A + u'圆整'    if len(strPartB)!= 0:        S = A + u'圆' +B    return S

 

转载地址:http://ocwsi.baihongyu.com/

你可能感兴趣的文章
注册表修改DOS的编码页为utf-8
查看>>
matplotlib.pyplot.plot()参数详解
查看>>
拉格朗日对偶问题详解
查看>>
MFC矩阵运算
查看>>
最小二乘法拟合:原理,python源码,C++源码
查看>>
ubuntu 安装mysql
查看>>
c# 计算器
查看>>
C# 简单的矩阵运算
查看>>
gcc 常用选项详解
查看>>
c++输入文件流ifstream用法详解
查看>>
c++输出文件流ofstream用法详解
查看>>
字符编码:ASCII,Unicode 和 UTF-8
查看>>
QT跨MinGW和MSVC两种编译器的解决办法
查看>>
firewalld的基本使用
查看>>
Linux下SVN客户端使用教程
查看>>
i2c-tools
查看>>
Linux分区方案
查看>>
nc 命令详解
查看>>
如何使用 systemd 中的定时器
查看>>
git命令速查表
查看>>