如何用Java编程实现人民币大小写转换?

 我来答
匿名用户
2013-07-16
展开全部
public String GetBigMoney(double eSender)
{
double NewMoney;
int Index, len, flag;
String StrTemp = null;
char[] p;
String Number[]={"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"};
String MonetaryUnit[] = {"万","仟","佰","拾","亿","仟","佰","拾","万","仟","佰","拾","元","角","分"} ;
NewMoney = Math.abs(eSender);
System.out.println(NewMoney);
DecimalFormat deciformat;
deciformat=(DecimalFormat)DecimalFormat.getInstance();
deciformat.applyPattern("#######");
String m = java.lang.String.valueOf(deciformat.format(NewMoney * 100));
int i;
if((i = m.indexOf('.')) != -1)
m = m.substring(0, i);
p = new char[m.length()];
//p = new char[40];
m.getChars(0, m.length(), p, 0);
//len=m.length();
if (NewMoney > 100000000000.00) {
StrTemp = ""; // FloatAsComma( NewMoney, False );
return StrTemp;
}
if (NewMoney < 0.01) {
StrTemp = "零";
return StrTemp;
}
if (eSender<0) {
StrTemp = "负";
}
else {
StrTemp = "";
}
flag = 1;
len =p.length;
System.out.println("1111");
System.out.println(len);
for (Index=(15-len);Index<15;Index++)
{
if (p[Index - 15 + len]!='0')
{
StrTemp = StrTemp + Number[Integer.parseInt(String.valueOf(p[Index-15+len]))];
StrTemp = StrTemp + MonetaryUnit[Index];
}
else
{
if (Index == 5)
{
if ((p[Index - 14 + len]!= '0') || (p[Index-13+len] != '0'))
{
StrTemp = StrTemp + MonetaryUnit[Index + 3];
flag = 0;
}

}
else
{
if ((Index == 12) ||( (Index == 8) && (flag ==1)) || (Index == 4))
{
StrTemp = StrTemp + MonetaryUnit[Index];
}
if ((p[Index-15 + len] != '0') && (Index != 14))
{
StrTemp = StrTemp +Number[Integer.parseInt(String.valueOf(p[Index-15+len]))];
;
}
}
}
}
if (p[m.length()-1] == '0')
{
StrTemp = StrTemp + "整";
}
return StrTemp;
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式