/**
* 将数字型货币转换为中文型货币
*
*
* String currency="1111111.111"
* String str = StringUtils.getCurrency2CN(currency)
* System.out.println(str); // "壹佰一十一万壹千壹佰一十一元一角一分"
*
public static String NumToRMBStr(String currencyNo, double val) throws Exception {
String SignStr = "";
String TailStr = "";
long fraction, integer;
int jiao, fen;
if (val < 0) {
val = -val;
SignStr = "负";
}
if (val > 99999999999999.999 || val < -99999999999999.999)
throw new Exception("数值指埋位数过大"); //数值位数过大
// 四舍五入到分
long temp = Math.round(val * 100);
integer = temp / 100;
fraction = temp % 100;
jiao = (int) fraction / 10;
fen = (int) fraction % 10;
if (jiao == 0 && fen == 0) {
TailStr = "整";
} else {
TailStr = HanDigiStr[jiao];
if (jiao != 0)
TailStr += "角";
if (integer == 0 && jiao == 0) // 零元后不写零几分
TailStr = "";
if (fen != 0)
TailStr += HanDigiStr[fen] + "分";
}
return SignStr + PositiveIntegerToHanStr(String.valueOf(integer)) + "元" + TailStr;
}
private static String HanDiviStr[] =
new String[] {
"",
"拾",
"佰",
"仟",
"万",
"拾",
"佰",
"仟拦盯",
"亿",
"拾",
"佰",
"仟",
"万",
"拾",
"佰",
"仟",
"亿",
"拾",
"佰",
"仟",
"万",
"拾",
"佰",
"仟" };
private static String PositiveIntegerToHanStr(String NumStr)
throws Exception { // 输入字符串必须正整数,只允许前导空格(必须右对齐),不宜有前导零
String RMBStr = "";
boolean lastzero = false;
boolean hasvalue = false; // 亿、万进位前有数值标记
int len, n;
len = NumStr.length();
if (len > 15)
throw new Exception("数值过大"); //数值过简逗和大
for (int i = len - 1; i >= 0; i--) {
if (NumStr.charAt(len - i - 1) == ' ')
continue;
n = NumStr.charAt(len - i - 1) - '0';
if (n < 0 || n > 9)
throw new Exception("输入含非数字字符"); //输入含非数字字符
if (n != 0) {
if (lastzero)
RMBStr += HanDigiStr[0]; // 若干零后若跟非零值,只显示一个零
// 除了亿万前的零不带到后面
//if( !( n==1 && (i%4)==1 && (lastzero || i==len-1) ) ) // 如十进位前有零也不发壹音用此行
if (!(n == 1 && (i % 4) == 1 && i == len - 1)) // 十进位处于第一位不发壹音
RMBStr += HanDigiStr[n];
RMBStr += HanDiviStr[i]; // 非零值后加进位,个位为空
hasvalue = true; // 置万进位前有值标记
} else {
if ((i % 8) == 0 || ((i % 8) == 4 && hasvalue)) { // 亿万之间必须有非零值方显示万
RMBStr += HanDiviStr[i]; // “亿”或“万”
hasvalue = false;
}
}
if ((i % 8) == 0 || (i % 8) == 4)
hasvalue = false;
lastzero = (n == 0) && (i % 4 != 0); // 亿万前有零后不加零,如:拾万贰仟
}
if (RMBStr.length() == 0)
return HanDigiStr[0]; // 输入空字符或"0",返回"零"
return RMBStr;
}
int money = 2038;
if(money==2038){
System.out.println("二清盯千答行和零三十带知八元整");
}
public class no4 {
public static void main(String[] args) {
// 金额大小写转换
float money=2038.0f;
int m1,m2,m3,m4,m5,m6,temp;
temp = (int)(money*100);
System.out.println(money);
m1 =temp%1000000/100000;
m2 =temp%100000/10000;
m3 =temp%10000/游族慧1000;
m4 =temp%1000/100;
m5 =temp%100/10;
m6 =temp%10;
char c1,c2,c3,c4,c5,c6;
c1=transe(m1);
c2=transe(m2);
c3=transe(m3);
c4=transe(m4);
c5=transe(m5);
c6=transe(m6);
String str="";
if(m1!=0)
{
str+=c1+"千";
}
if(m2!=0)
{
str+=c2+"神答百";
}
if(m1!=0&&m2==0&&(m3!=0||m4!=0))
{
str+="零";
}
if(m3!=0)
{
str+=c3+"十";
}
if(m2!=0&&m3==0&&m4!=0)
{
str+="零";
}
if(m4!=0)
{
str+=c4;
}
str+="元";
if(m5 ==0&&m6 ==0)
{
str+="整";
}
if(m5!=0)
{
str+=c5+"角";
}
if(m5==0&&m6!=0)
{
str+="零穗手";
}
if(m6!=0)
{
str+=c6+"分";
}
System.out.print(str+"\n");
System.out.println("..........................");
}
public static char transe(int m)
{
char r=' ';
switch (m)
{
case 0:
r ='零';
break;
case 1:
r ='壹';
break;
case 2:
r ='贰';
break;
case 3:
r ='叁';
break;
case 4:
r ='肆';
break;
case 5:
r ='伍';
break;
case 6:
r ='陆';
break;
case 7:
r ='柒';
break;
case 8:
r ='捌';
break;
case 9:
r ='玖';
break;
}
return r;
}
}