java递归算法实现 数字人民币大写转换
最近穷死了 ,没钱吃饭ing 写点钱给自己吧!
public class Test{
public static String getChar(long a){
int b = (int)a;
Map map = new HashMap();
map.put(0,"零");
map.put(1,"壹");
map.put(2,"贰");
map.put(3,"叁");
map.put(4,"肆");
map.put(5,"伍");
map.put(6,"陆");
map.put(7,"柒");
map.put(8,"捌");
map.put(9,"玖");
return map.get(b).toString();
} public static void main(String args[]) throws Exception {
String chinese0 = getChineseMoney(1007L);
System.out.println("我有"+chinese0 + "圓"); String chinese = getChineseMoney(10155530665347L);
System.out.println("我有"+chinese + "圓"); String chinese2 = getChineseMoney(10100065347L);
System.out.println("我有"+chinese2 +"圓"); String chinese3 = getChineseMoney(1013333223300065347L);
System.out.println("我穷死了。"+chinese3 +"圓");
} public static String getChineseMoney(long alb){
int len = String.valueOf(alb).length();
switch (len){
case 1:
return getChar(alb);
case 2:
return alb % 10 == 0 ? (alb/10 == 1 ? "": getChar(alb/10))+"拾" : getChar(alb/10)+"拾" +getChar(alb%10);
case 3:
if( alb % 100 == 0) {
return getChar(alb / 100) + "佰";
}
if(String.valueOf(alb).charAt(1) == '0'){
return getChar(alb / 100) + "佰"+getChar(0)+getChar(alb % 100);
}else{
return getChar(alb / 100) + "佰" + getChineseMoney(alb % 100);
}
case 4:
if( alb % 1000 == 0) {
return getChar(alb / 1000) + "仟";
}
if(String.valueOf(alb).charAt(1) == '0' && String.valueOf(alb).charAt(2) == '0'){
return getChar(alb / 1000) + "仟"+getChar(0)+getChar(alb % 100);
}else if(String.valueOf(alb).charAt(1) == '0'){
return getChar(alb / 1000) + "仟" + getChar(0) + getChineseMoney(alb % 100);
} else {
return getChar(alb / 1000) + "仟" + getChineseMoney(alb % 1000);
}
case 5: case 6: case 7: case 8:
return getChineseMoney(alb / 10000) + "万" + getChineseMoney(alb % 10000);
case 9: case 10: case 11: case 12:
return getChineseMoney(alb/(10000*10000L)) + "亿" + getChineseMoney(alb % (10000*10000L));
case 13: case 14: case 15:
return getChineseMoney(alb/(10000*10000*10000L)) + "万" + getChineseMoney(alb % (10000*10000*10000L));
default:
return "我穷的只剩下钱了,自己无聊的话加上去吧!";
}
}
}
java递归算法实现 数字人民币大写转换的更多相关文章
- python实现人民币大写转换
问题描述: 银行在打印票据的时候,常常需要将阿拉伯数字表示的人民币金额转换为大写表示,现在请你来完成这样一个程序. 在中文大写方式中,0到10以及100.1000.10000被依次表示为: 零 壹 贰 ...
- FastReport调用Delphi中的人民币大写转换自定义函数
FastReport调用Delphi中的人民币大写转换自定义函数 FastReport调用Delphi中的人民币大写转换自定义函数 function TJzpzEdit1.MoneyCn(mmje ...
- 用python实现把数字人民币金额转换成大写的脚本程序
# -*- coding: utf-8 -*- def Num2MoneyFormat( change_number ): """ .转换数字为大写货币格式( forma ...
- 【办公-Word-VB】人民币大写转换-带完整注释
完整代码见:我的CSDN博客 -------------------- 应公司财务人员的请求,需在Word中做个:输入阿拉伯数字,自动转换成大写,并填充到Word控件中对应的亿.万.千控件格子的功能, ...
- Java递归算法——三角数字(消除递归)
import java.io.*; // for I/O //类名:Params //属性: //方法: class Params //这个类的对象被压入栈中 { public int n; //用来 ...
- Java递归算法——三角数字
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.i ...
- Java实现将数字转为大写汉字
public class Int2Big { static String int2big(int src) { final String num[] = {"零", "壹 ...
- Java实现人民币大写精讲
想要实现人民币大写,在发票等场景中使用?? 1234.56显示为:壹仟贰佰叁拾肆元伍角陆分,那就往下看看吧! 本程序可以实现 0 到 9999 9999 9999.994 以内的人民币大写转换,精确到 ...
- Java实现人民币大写代码解析
想要实现人民币大写,在发票等场景中使用?? 1234.56显示为:壹仟贰佰叁拾肆元伍角陆分,那就往下看看吧! 本程序可以实现 0 到 9999 9999 9999.994 以内的人民币大写转换,精确到 ...
随机推荐
- poj3304计算几何直线与线段关系
Given n segments in the two dimensional space, write a program, which determines if there exists a l ...
- LNMP源码编译安装
思路:根据Linux系统以及公司网站系统的信息,选择合适的安装包进行安装 一.查看系统信息 # uname -a # 查看内核/操作系统/CPU信息 # ...
- 精益IT组织与分享式领导
精益IT组织 未来的组织将专注于同行业的产品或业务流--其他的一切,包括专家和管理者在内,都是为了让一线工作人员可以第一时间就做好,而又不会遇到任何麻烦.最大的制约不是技术:真正的挑战是变 ...
- Ubuntu14.04安装samba
Ubuntu14.04安装samba 按照惯例,首先介绍Samba.Samba是在Linux系统上实现的SMB(Server Messages Block,信息服务块)协议的一款免费软件.它实现在局域 ...
- 云计算之路-阿里云上:攻击又来了,4个IP分别遭遇超过30G的流量攻击
继5月13日下午被攻击之后,今天下午,攻击又肆无忌惮地来了,14:35.14:39.14:40.14:41 ,依次有4个IP遭遇超过30G的流量攻击,被阿里云“云盾”关进“黑洞”,造成被攻击IP上的站 ...
- win10+ubuntu17.04双系统安装与卸载(uefi+gpt)及常见软件安装
换了台笔记本,重新装了下系统.配置是i7 6700hq+gtx965m,重装了下双系统. 之前老机器是大一时候买的,装得是win7+ubuntu19.04(mbr+bios).新机器到手,想法是装了w ...
- Spring Cloud 注册中心Eureka
一.简介 最近在看Spring Cloud微服务,接下来的时间和大家一起分享我所看到的,公司现在用的是dubbo ,之后有时间也去了解了解dubbo的源码.与dubbo相比较,Spring Cloud ...
- Java Garbage Collectors
Generational Collectors (分代收集器) GC algos optimised based on two hypotheses / observations: Most obje ...
- Linux parent process and child process when 'sudo'
如果在一般用户下如user,执行sudo命令,会产生两个进程. ps -ef | grep Container root 4305 643 0 16:37 pts/39 00:00:00 sudo . ...
- bzoj 4765 普通计算姬(树状数组 + 分块)
http://www.lydsy.com/JudgeOnline/problem.php?id=4765 很nice的一道题啊(可能是因为卡了n久终于做出来了 题意就是给你一棵带点权的有根树,sum( ...