人民币小写转大写
来源:互联网 发布:南方和北方的区别知乎 编辑:程序博客网 时间:2024/04/30 00:57
package day00;
public class Money{//人民币小写转大写
public static String zheng(int str,String temp,String s,String n){//处理整数部分
int n1=0;
String num="";
String com="";
String result=""; //返回的结果
if(temp.length()>15){
result="超出范围";
}else{
for(int i=0;i<str;i++){
n1=Integer.parseInt(String.valueOf(temp.charAt(i)));
num=s.substring(n1,n1+1);
n1=str-i+1;
com=n.substring(n1,n1+1);
result=result.concat(num).concat(com);
}
//从千亿到亿
result=result.replaceAll("零仟","");
result=result.replaceAll("零佰","零");
result=result.replaceAll("零拾","零");
result=result.replaceAll("零零","零");
result=result.replaceAll("零零","零");
result=result.replaceAll("零亿","亿");
if(result.charAt(0)=='零'){
result=result.replaceAll("零","");
}
if(result.charAt(0)=='亿'){
result=result.replaceAll("亿","");
}
//从千万到万
result=result.replaceAll("零仟","零");
result=result.replaceAll("零佰","零");
result=result.replaceAll("零拾","零");
result=result.replaceAll("零零","零");
result=result.replaceAll("零零","零");
result=result.replaceAll("零万","万");
result=result.replaceAll("亿万","亿");
if(result.charAt(0)=='万'){
result=result.replaceAll("万","");
}
//从千到个位
result=result.replaceAll("零仟","零");
result=result.replaceAll("零佰","零");
result=result.replaceAll("零拾","零");
result=result.replaceAll("零零","零");
result=result.replaceAll("零零","零");
result=result.replaceAll("零元","元");
}
return result;
}
public static String fen(int str,String temp,String s,String n){//处理小数部分
int n1=0;
String num="";
String com="";
String result=""; //返回的结果
for(int i=str;i<str+2;i++){
n1=Integer.parseInt(String.valueOf(temp.charAt(i+1)));
num=s.substring(n1,n1+1);
n1=str-i+1;
com=n.substring(n1,n1+1);
result=result.concat(num).concat(com);
}
result=result.replaceAll("零角","零");
result=result.replaceAll("零分","零");
result=result.replaceAll("角零","角");
if(result.equals("零零")){
result=result.replaceAll("零零","");
result=result.concat("整");
}
return result;
}
public static void main(String[] args){
String moneys="3999.00";
String s="零壹贰叁肆伍陆柒捌玖";
String n="分角元拾佰仟万拾佰仟亿拾佰仟";
String temp=""; //去掉前后空格
int position=0;
position=moneys.indexOf(".") ; //小数点的位置 ,从零开始
int str=0;
temp=moneys.trim(); //去除前后空格
if(position==-1){//无小数
str=temp.length(); //钱的长度
System.out.print(zheng(str,temp,s,n));
System.out.print("整");
}else{
str=temp.indexOf(".");
String a=zheng(str,temp,s,n); //整数部分
String b=fen(str,temp,s,n); //处理小数部分
String result=a.concat(b);
if(result.charAt(0)=='元'&& result.charAt(1)=='零'){
result=result.replaceAll("元零","");
}
if(result.charAt(0)=='元'&& result.charAt(1)=='整'){
result=result.replaceAll("元整","零元整");
}
System.out.print(result);
}
}
}
- 人民币小写转大写
- 人民币小写转大写
- 人民币小写转大写
- 人民币小写转大写
- 人民币小写转大写
- 人民币小写转大写
- 人民币小写转大写
- 人民币小写转大写
- 人民币小写转大写
- 人民币小写转大写
- 人民币小写金额转大写
- 人民币小写金额转大写
- 人民币小写金额转大写
- 人民币小写转大写代码
- 人民币小写转大写(java)
- Java人民币小写转大写
- 人民币小写转大写 java
- 人民币小写金额转大写
- c语言练习4
- apache 修改网页后缀名
- 关于C++程序命名规范
- linq 查找控件
- 程序的编写思路一定要清晰
- 人民币小写转大写
- 一步步教你如何用疯狂.NET架构中的通用权限系统 -- 分级授权
- 拯救你的字符串:发给Bjarne的信,大家来帮我评价一下
- 让老婆成为最幸福女人的做法
- 心情不好
- 修改boa对单个上传文件大小的限制
- 一个很短的故事,值得你一看
- 人生21个最难
- php 页面跳转