数字转人民币读法-python3
"""
2 把一个浮点数分解成证书备份和小数部分
3 """
4 def divide(num):
5 intnum = int(num)
6 floatnum = int(num) - intnum
7 return (str(intnum),str(floatnum))
8
9 han_list = ["零","壹","贰","叁","肆","伍","陆","柒","捌","玖"]
10 unit_list = ["千","佰","拾"]
11
12 def convert(num):
13 result = ""
14 num_len = len(num)
15 for i in range(num_len):
16 number = int(num[i])
17 if num_len == 4 and number != 0 and i <= 2:
18 result += han_list[number] + unit_list[i]
19 elif num_len == 3 and number != 0 and i <2:
20 result += han_list[number] + unit_list[i + 1]
21 elif num_len == 2 and number != 0 and i <1:
22 result += han_list[number] + unit_list[i + 2]
23 else:
24 result += han_list[number]
25 return result
26 def convert2(num):
27 lennum = len(num)
28 if lennum > 12:
29 print("数字太大无法转换!")
30 return
31 elif lennum > 8:
32 return convert(num[:-8]) + "亿"+\
33 convert(num[-8:-4]) + "万"+\
34 convert(num[-4:])
35 elif lennum > 4:
36 return convert(num[:-4]) + "万"+\
37 convert(num[-4:])
38 else:
else:
39 return convert(num)
40 number = input()
41 intnum,floatnum = divide(number)
42 result = convert2(intnum)+ "元"
43
44 print(result)
运行结果
123456789
壹亿贰千叁佰肆拾伍万陆千柒佰捌拾玖元
一开始想用if嵌套来实现这个功能,后俩发现程序量过于大,所以就换了一种思如,附上代码,这个代码只实现了8为以上数字的转换
"""
2 问题描述
3 将一个数字转换成人命币的读法,并且数字要求转换为对应的大写数字
4 思路分析
5 1.详见其整数和小数分离出来
6 2.中国习惯将数字每四位划分为一个区间
7 3.
8 """
9 list1 = []
10 def sever_number(number):
11 int_number = int(number)
12 float_number =int(number) - int_number
13 #将其转化为字符串,以进行切片
14 return (str(int_number),str(float_number))
15 list_han = ["零","壹","贰","叁","肆","伍","陆","柒","捌","玖"]
16 list_unit = ["千","佰","拾"]
17
18 def hanstr(number):
19 global list1
20 if len(number) > 8:
21 sever1 = number[:-8]
22 for i in sever1:
23 num = int(i)
24 a = list_han[num]
25 list1.append(a)
26 if sever1.index(i) == (len(sever1) - 1):
27 list1.append(list_unit[0])
28 sever2 = number[-8:-4]
29 for i in sever2:
30 num = int(i)
31 a = list_han[num]
32 list1.append(a)
33 if sever2.index(i) == (len(sever2) - 1):
34 sever3 = number[-4:]
35 for i in sever3:
36 num = int(i)
37 a = list_han[num]
38 list1.append(a)
39 return
40 num = input()
41 int_number,float_number = sever_number(num)
42 hanstr(int_number)
43 for i in list1:
44 print(i,end = "")
45 print("\n")
46
47
~
数字转人民币读法-python3的更多相关文章
- Python学习之--数字转人民币读法(解决问题的方法很重要)
效果图: 实现代码: money = float(input("Please input the money:"))cop = int(money)Num = ['零','壹',' ...
- java人民币读法转换
实现浮点数转换成人民币读法字符串 编写一个程序,将浮点数转换成人民币读法字符串,例如,将1006.333转换为壹千零陆元叁角叁分. 题意分析: 将浮点数分成整数部分和小数部分,分开处理整数部分和小数部 ...
- ORACLE数字转换人民币大写
ORACLE 数字转换人民币大写 示例. 数字 :183066999230.68 人民币大写 :壹仟捌佰参拾亿陆仟陆佰玖拾玖万玖仟贰佰参 ...
- 数字转人民币大写(SQL SERVER)
--数字转人民币大写NumToRMB ---新建方法create FUNCTION dbo.NumToRMB (@num numeric(14,5)) RETURNS varchar(100) ...
- php数字转人民币金额大写
numToRmb.php <?php header("content-type:text/html;charset=utf-8"); function numToRmb($n ...
- sql 数字转人民币大写函数(两种方法)
,)) returns @rmb table( 亿 ) ,仟万 ) ,佰万 ) ,拾万 ) ,万 ) ,仟 ) ,佰 ) ,拾 ) ,元 ) ,角 ) ,分 )) as begin insert in ...
- 将一个浮点数转换成人民币读法字符串(java)
public class Num2Rmb { private String[] hanArr = {"零" , "壹" , "贰&qu ...
- 一个用php写的人民币数字转人民币大写的函数
function num2rmb ($num) { $c1 = "零壹贰叁肆伍陆柒捌玖"; $c2 = "分角元拾佰仟万拾佰仟亿"; ...
- 树莓派项目(三) 数字识别树莓派3+python3.5+opencv3.3+tensorflow1.7+keras
https://blog.csdn.net/weixin_40707450/article/details/80290705
随机推荐
- 解决springmvc使用@ResponseBody返回String类型字符串中文乱码问题
问题分析: 首先: 确定的是只有当返回值是 String时才会出现中文乱码,而当返回值是Map<String, Object>或者是其它类型时,并没有中文乱码的出现. 然后找原因: 原因是 ...
- matplotlib 单figure多图
method 1 import numpy as np import matplotlib.pyplot as plt fg, axes = plt.subplots(1, 2, figsize=(1 ...
- NMAP 使用教程!,nmap [Scan Type(s)] [Options] {target specification} , nmap -sn 192.168.2.0/24 , raspberry pi 3
NMAP 使用教程 https://nmap.org/man/zh/man-briefoptions.html 当Nmap不带选项运行时,该选项概要会被输出,最新的版本在这里 http://www.i ...
- CSS 设置多行文本省略号 ...
CSS 设置多行文本省略号 ... .box{ display: -webkit-box; overflow: hidden; text-overflow: ellipsis; word-wrap: ...
- OpenCV & Web Assembly & Web Worker
OpenCV & Web Assembly & Web Worker opencv-in-the-web https://aralroca.com/blog/opencv-in-the ...
- Web Components & HTML5 & template & slot
Web Components & HTML5 & template & slot https://developer.mozilla.org/en-US/docs/Web/HT ...
- ws & websocket & 掉线重连
ws & websocket & 掉线重连 reconnecting websocket https://github.com/joewalnes/reconnecting-webso ...
- css & clip-path
css & clip-path https://developer.mozilla.org/en-US/docs/Web/CSS/clip-path https://tongqu.me/ tw ...
- 在线预览word,excel,ppt
https://view.officeapps.live.com/op/view.aspx?src=服务器地址微软提供的地址拼接自己的可以预览了拼接自己的服务器地址可以在线预览
- ng mock服务器数据
angualr文档 in-memory-web-api 文档 安装 yarn add angular-in-memory-web-api -S src/app/app.module.ts import ...