RMB转换大写 原

裸奔的八戒

public class RMB{

private final static String[] STR_NUMBER = { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" };

private final static String[] STR_UNIT = { "", "拾", "佰", "仟", "万", "拾","佰", "仟", "亿", "拾", "佰", "仟" };// 整数单位

private final static String[] STR_UNIT2 = { "角", "分", "厘" };// 小数单位

public static void main(String[] args) {

// TODO Auto-generated method stub

Scanner scan= new Scanner(System.in);

String convert=convert(scan.nextDouble());

System.out.println(convert);

}

public static boolean IsNumber(String str){

char[] c=str.toCharArray();

for(int i=0;i<c.length;i++){

if(Character.isDigit(c[i])){

}else{

return false;

}

}

return true;

}

public static String convert(double d){

DecimalFormat df=new DecimalFormat("#0.###");

String strNum=df.format(d);

if(strNum.indexOf(".")!=-1){

String num=strNum.substring(0, strNum.indexOf("."));

if(num.length()>12){

System.out.println("number is too big,can not be convert!");

return "";

}

}

String point="";

if(strNum.indexOf(".")!=-1){

point="元";

}else{

point="元整";

}

String result=getInteger(strNum)+point+getDecimal(strNum);

if(result.startsWith("元")){

result=result.substring(1, result.length());

}

return result;

}

public static String getInteger(String num){

if(num.indexOf(".")!=-1){

num=num.substring(0,num.indexOf("."));

}

num=new StringBuffer(num).reverse().toString();

StringBuffer temp=new StringBuffer();

for(int i=0;i<num.length();i++){

temp.append(STR_UNIT[i]);

temp.append(STR_NUMBER[num.charAt(i)-48]);

}

num=temp.reverse().toString();

num=numReplace(num,"零拾","零");

num=numReplace(num,"零佰","零");

num=numReplace(num,"零仟","零");

num=numReplace(num,"零万","万");

num=numReplace(num,"零亿","亿");

num=numReplace(num,"零零","零");

num=numReplace(num,"亿万","亿");

if(num.lastIndexOf("零")==num.length()-1){

num=num.substring(0,num.length()-1);

}

return num;

}

public static String getDecimal(String num){

if (num.indexOf(".") == -1){

return "";

}

num = num.substring(num.indexOf(".") + 1);

num = new StringBuffer(num).reverse().toString();

StringBuffer temp = new StringBuffer();

for (int i = 0; i < num.length(); i++){

temp.append(STR_NUMBER[num.charAt(i) - 48]);

temp.append(STR_UNIT2[i]);

}

num = temp.toString();

num = numReplace(num, "零角", "零");

num = numReplace(num, "零分", "零");

num = numReplace(num, "零厘", "零");

num = numReplace(num, "零零", "零");

if (num.lastIndexOf("零") == num.length() - 1){

num = num.substring(0, num.length() - 1);

}

return num;

}

public static String numReplace(String num, String oldStr, String newStr){

while(true){

if (num.indexOf(oldStr) == -1){

break;

}

num = num.replaceAll(oldStr, newStr);

}

return num;

}

}

裸奔的八戒

CCFLOW如何使用“脚本验证”自动填写表单中的RMB（大写）金额字段

ccflow
2015/07/28
0
0

2017/10/02
0
0

ryan_bai
2017/09/23
0
0
Swift3.0语言教程字符串大小写转化

Swift3.0语言教程字符串大小写转化 Swift3.0语言教程字符串大小写转化，在字符串中，字符串的格式是很重要的，例如首字母大写，全部大写以及全部小写等。当字符串中字符很多时，通过人为一个...

2016/11/16
2
0

A - Frog 鸡兔同笼问题 B - Triangles 一共给了六个点，前三个点是第一个三角形，后三个点是第二个三角形。 题意：判断两个三角形的关系，相交，内含或相离 对第一个三角形的每一条边和第二个...

akatsuki__itachi
04/30
0
0

CDH安装SENTRY

1. 背景 虽然在集群上部署了kerberos认证，但是kerberos只是对用户层面进行认证，凡是认证通过的用户都有全量的访问权限，这很不安全，需要进一步对用户的权限进行控制，Sentry 的作用就是这...

hblt-j
12分钟前
0
0
Ubuntu 18.04 PostgreSQL 11 apt 默认安装某些问题解析

13分钟前
0
0

Anur
16分钟前
0
0

https://wenku.baidu.com/view/b1bb67f1f90f76c661371a75.html?sxts=1544696459935

whoisliang
19分钟前
0
0
rabbitmq学习

35分钟前
1
0