分析

  • 分小数和整数部分进行处理
  • 末尾的零应舍弃
  • 中间有连续多个零,只取一个零
  • 整数部分从右往左以4位为步长扫描

实现

# -*- coding: utf-8 -*-
from __future__ import unicode_literalsdef convert(n):units = ['', '万', '亿']nums = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖']decimal_label = ['角', '分']small_int_label = ['', '拾', '佰', '仟']int_part, decimal_part = str(int(n)), str(n - int(n))[2:]  # 分离整数和小数部分res = []if decimal_part:res.append(''.join([nums[int(x)] + y for x, y in zip(decimal_part, decimal_label) if x != '0']))if int_part != '0':res.append('圆')while int_part:small_int_part, int_part = int_part[-4:], int_part[:-4]tmp = ''.join([nums[int(x)] + (y if x != '0' else '') for x, y in zip(small_int_part[::-1], small_int_label)[::-1]])tmp = tmp.rstrip('零').replace('零零零', '零').replace('零零', '零')unit = units.pop(0)if tmp:tmp += unitres.append(tmp)return ''.join(res[::-1])print convert(0.22)
print convert(0.20)
print convert(0.02)print convert(1)
print convert(12)
print convert(123)
print convert(1234)
print convert(1230)
print convert(1204)
print convert(1034)
print convert(1004)print convert(51234)
print convert(51204)
print convert(51034)
print convert(50234)
print convert(50034)
print convert(50004)
print convert(50000)print convert(12351234)
print convert(12301234)
print convert(12351234)
print convert(12051234)
print convert(10351234)
print convert(10051234)
print convert(10001234)
print convert(10000000)
print convert(10000004)
print convert(10000030)
print convert(10000200)
print convert(10001000)
print convert(10050000)print convert(12000010001)
print convert(1409.50)

输出:
贰角贰分
贰角
贰分
壹圆
壹拾贰圆
壹佰贰拾叁圆
壹仟贰佰叁拾肆圆
壹仟贰佰叁拾圆
壹仟贰佰零肆圆
壹仟零叁拾肆圆
壹仟零肆圆
伍万壹仟贰佰叁拾肆圆
伍万壹仟贰佰零肆圆
伍万壹仟零叁拾肆圆
伍万零贰佰叁拾肆圆
伍万零叁拾肆圆
伍万零肆圆
伍万圆
壹仟贰佰叁拾伍万壹仟贰佰叁拾肆圆
壹仟贰佰叁拾万壹仟贰佰叁拾肆圆
壹仟贰佰叁拾伍万壹仟贰佰叁拾肆圆
壹仟贰佰零伍万壹仟贰佰叁拾肆圆
壹仟零叁拾伍万壹仟贰佰叁拾肆圆
壹仟零伍万壹仟贰佰叁拾肆圆
壹仟万壹仟贰佰叁拾肆圆
壹仟万圆
壹仟万零肆圆
壹仟万零叁拾圆
壹仟万零贰佰圆
壹仟万壹仟圆
壹仟零伍万圆
壹佰贰拾亿零壹万零壹圆
壹仟肆佰零玖圆伍角

阿拉伯数字金额转中文大写 (python实现)相关推荐

  1. python数字转换为大写中文_阿拉伯数字金额转中文大写 (python实现)

    分析 实现 # -*- coding: utf-8 -*- from __future__ import unicode_literals def convert(n): units = ['', ' ...

  2. 阿拉伯数字金额转换为中文大写

    function digitUppercase(n) {var fraction = ['角', '分'];var digit = ['零', '壹', '贰', '叁', '肆','伍', '陆', ...

  3. python人民币小写转大写_人民币金额转中文大写 (python实现)

    https://blog.csdn.net/handsomekang/article/details/52563487?depth_1-utm_source=distribute.pc_relevan ...

  4. Python将阿拉伯数字转化为中文大写

    利用Python将阿拉伯数字转化为中文大写,其实最麻烦的地方就是中间空多个0的问题,这种情况下,采用拆分法则,将一个大数字,先拆分成整数部分和小数部分,再对整数部分按照仟.万.亿.兆分位拆分为四个字符 ...

  5. 【工具封装】Python 实现将阿拉伯数字 === 转换成中文大写数字

    一.序言:   工具封装第四弹,阿拉伯数字 ===> 转换成 ===> 中文大写数字,喜欢就赶紧收藏+点赞+关注吧 !!! ---- Nick.Peng 二.实现代码如下: #!/usr/ ...

  6. 正则也很牛,把阿拉伯数字的金额转换为中文大写数字

    using System; using System.Text.RegularExpressions; class Program {   // 把阿拉伯数字的金额转换为中文大写数字   static ...

  7. 输入数字怎么变成大写python_Python将阿拉伯数字转化为中文大写

    利用Python将阿拉伯数字转化为中文大写,其实最麻烦的地方就是中间空多个0的问题,这种情况下,采用拆分法则,将一个大数字,先拆分成整数部分和小 数部分,再对整数部分按照仟.万.亿.兆分位拆分为四个字 ...

  8. SDNUOJ 1213.金额的中文大写

    今天做了一个题,感觉网上的程序有些繁琐或者不够简明,所以打算把自己的发上来,供大家借鉴. 前几天学校的OJ坏了,刚刚修好我便看到了这个题. 1213.金额的中文大写 Time Limit: 1000 ...

  9. C# 金额转中文大写

    今天看到一个库是把金额转中文大写,看起来很容易,所以我就自己写了 创建的项目是创建一个 dot net core 的项目,实际上这个项目可以创建为 Stand 的. 首先创建类,这个类的构造传入一个 ...

最新文章

  1. timeout connect 10000 # default 10 second time out if a backend is not found
  2. CentOS5.6配置salt节点minion
  3. 〈转贴〉如何解决 Windows XP 中的硬件和软件驱动程序问题
  4. pip install时发生raise ReadTimeoutError(self._pool, None, 'Read timed out.')的解决方案
  5. Android 系统(230)---View 绘制流程 —— 基础(1)
  6. 真无线蓝牙耳机霸主之争:苹果AirPods和索尼WF-1000XM3怎么选?
  7. 中国酸性蒸汽清洗系统市场趋势报告、技术动态创新及市场预测
  8. 5 kvm虚拟磁盘扩容
  9. 腾讯云最新10元/月有效期到2018年8月20日
  10. uniapp小程序根据经纬度精确定位
  11. 邮件到达对方服务器但是没到邮箱,无法将邮件发送进到对方服务器,教你如何用手工探测...
  12. Minecraft mod制作简易教程(四)——创建一个方块
  13. 有吧友需要PDF的下载站点,好吧,我这边汇总一下
  14. 第15章-4~6 装配体静力学分析经验技巧总结篇 (工作原理的简化、约束、预紧力、载荷、后处理)高效修改接触对、suppress(抑制)、多工位(多步计算)的螺栓预紧力设置
  15. 鸿图之下服务器维护10月25,鸿图之下11月25日维护更新公告
  16. Embedding Propagation: Smoother Manifold for Few-Shot Classification ECCV 2020
  17. 手机App开发的基础概念
  18. Git中pull操作
  19. 掌握成为优秀财务的核心能力
  20. scratch/mblock项目:跑酷闯关(侦测、条件语句、数据与变量的应用)

热门文章

  1. 解决微信群服务管理难题,只需要一个助手
  2. java与c的交互,java与c/c++之间的数据交互,java交互
  3. 函数调用过程中函数栈详解
  4. Shiro的Java原生反序列化漏洞
  5. 服务器多出mysql帐户_在一台服务器构建多mysql 服务
  6. 计算跑步时的能量消耗(卡路里和千焦的换算公式)
  7. linux下easyconnect启动不能连接外网
  8. 谷歌、亚马逊全面开火,一场前所未有的AI芯片大战
  9. Assignment | 05-week3 -Part_2-Trigger Word Detection
  10. AUTOCAD——图纸歪了如何对齐