请把该段代码转换成JavaScript函数(200分)

  • 主题发起人 主题发起人 Emily
  • 开始时间 开始时间
E

Emily

Unregistered / Unconfirmed
GUEST, unregistred user!
该功能实现小写金额转换为大写金额,急急急!!!!!!
public static final String moneyToUpper(double aje)
{
int i,lendec,lenint;
String numstr,a,b,c,d,bbak="";
NumberFormat nf = NumberFormat.getInstance();
DecimalFormat df = (DecimalFormat)nf;
String pattern = "#0.00";
df.applyPattern(pattern);
numstr = df.format(aje);
lenint=numstr.indexOf(".");
if (numstr.endsWith(".00"))
lendec=0;
else
lendec=2;
String dxint[]=new String[13],dxdec[]=new String[2],sz[]=new String[13];
String dxstr="万仟佰拾亿仟佰拾万仟佰拾元";
String szstr="零壹贰叁肆伍陆柒捌玖";
for (i=0 ;i<13;
i++){

dxint=dxstr.substring(13 - i -1,13 - i);
if (i<10)

sz=szstr.substring(i ,i+1);
else
sz=" ";
}
dxdec[0]="角";
dxdec[1]="分";
dxstr=" ";
for (i = 0 ;i< lenint;i++){
a = numstr.substring(i,i+1);
b = sz[Integer.parseInt(a)];
c = dxint[lenint - i -1];
if (!dxstr.equals(" "))
d = dxstr.substring(dxstr.length() - 1 ,dxstr.length());
else
d = " ";
if (b.equals("零") &amp;&amp;
(d.equals("零") || b.equals(bbak) || c.equals("元") || c.equals("万") || c.equals("亿"))) b= "";
if (a.equals("0") &amp;&amp;
!c.equals("元") &amp;&amp;
!c.equals("万") &amp;&amp;
!c.equals("亿") ) c="";
if ((c.equals("元") || c.equals("万") || c.equals("亿")) &amp;&amp;
d.equals("零") &amp;&amp;
a.equals("0")){
dxstr=dxstr.substring( 0,dxstr.length() - 1);
d = dxstr.substring(dxstr.length() - 1,dxstr.length());
if (c.equals("元") &amp;&amp;
d.equals("万") || c.equals("万") &amp;&amp;
d.equals("亿")) c="";
}
dxstr=dxstr + b + c;
bbak = b;
}
for (i=0 ;i< lendec;i++){

a = numstr.substring(lenint+2-1,lenint+2-1+lendec).substring(i,i+1);
if (a.equals("0") &amp;&amp;
dxdec.equals("分"))
b="";
else
b=sz[Integer.parseInt(a)];
if (!a.equals("0"))
dxstr=dxstr+b+dxdec;
else
dxstr=dxstr+b;
}
if (lendec==0) dxstr=dxstr+"整";
return dxstr;
}
 
后退
顶部