小写钱转大写钱

ContractGrid.jsp(在jsp中调用JAVA),这个JSP是个表格。表格里有钱数。

<table align="center"width="80%"id="border" border="0" cellspacing="0"   >
 <Div>
<Script Language="javascript">
 
 function CheckIsNum(szMode,currow){
  if (szMode == 1){
   if (isNaN(document.all["Qty_Edit"+currow].value) || document.all["Qty_Edit"+currow].value == "")
    document.all["Qty_Edit"+currow].value = 0;
   else
    document.all["Qty_Edit"+currow].value = Math.round(document.all["Qty_Edit"+currow].value)    
  }
  if (szMode == 2){
   if (isNaN(document.all["Price_Edit"+currow].value) || document.all["Price_Edit"+currow].value == "")
    document.all["Price_Edit"+currow].value = 0;
   else
    document.all["Price_Edit"+currow].value = Math.round(document.all["Price_Edit"+currow].value * 100 )/100    
  }
  if (szMode == 5){
     if (isNaN(document.all["Qty_Edita"+currow].value) || document.all["Qty_Edita"+currow].value == "")
    document.all["Qty_Edita"+currow].value = 0;
     else
     document.all["Qty_Edita"+currow].value = Math.round(document.all["Qty_Edita"+currow].value)    
  }
  if (szMode == 4){
   if (isNaN(document.all["Price_Edita"+currow].value) || document.all["Price_Edita"+currow].value == "")
    document.all["Price_Edita"+currow].value = 0;
   else
    document.all["Price_Edita"+currow].value = Math.round(document.all["Price_Edita"+currow].value * 100 )/100    
  }
 }
 
 function GridSaveCheck(){
  for (var i=1;i<=50;i++){
   if (document.all["FullName_Edit"+i] != null && document.all["FullName_Edit"+i].value != ""){    
    if (document.all["Qty_Edit"+i].value == "" ){
     alert("No." + i + "行的商品的数量不是一个有效的值,请确认!");
     return false;
    }
    if (document.all["Price_Edit"+i].value == "" || eval(document.all["Price_Edit"+i].value) <= 0){
     alert("No." + i + "行的商品的价格不是一个有效的价格,请确认!");
     return false;
    }
   }
  }
  return true;
 }
 
 // 删除一行
 function DeleteRow(currow) {
  //alert(currow);
  document.all["CommidityTypeID" + currow].value = "";
  CommidityGrid.deleteRow(CommidityGrid.rows("GridRow" + currow).rowIndex);  
  GridSum(); // 重新计算合计值
 }
 
 //用于javascript里边算小数乘法的函数,两个参数
 function multiply(x,y){
  var str_x,str_y,int_x,int_y
  int_x = 1;
  int_y = 1; 
  str_x = x.toString();
  
  str_y = y.toString();
  if(str_x.indexOf(".")!=-1){
   int_x = Math.pow(10,parseInt(str_x.length-str_x.indexOf(".")-1))
   str_x = str_x.substr(0,str_x.indexOf("."))+str_x.substr(str_x.indexOf(".")+1,str_x.length)
  }
  
  if(str_y.indexOf(".")!=-1){
   int_y = Math.pow(10,parseInt(str_y.length-str_y.indexOf(".")-1))
   str_y = str_y.substr(0,str_y.indexOf("."))+str_y.substr(str_y.indexOf(".")+1,str_y.length)
  }
  return (str_x*str_y)/(int_x*int_y)
 }


 </Script>
 </Div>
 <tr width="80%"id="border" border="0" cellspacing="0"  class="ListTableHeader1">
  <td width="420" align="center"><%=codeToString("产品名称")%></td>
  <td width="190" align="center"><%=codeToString("商标牌号")%></td>
  <td width="190" align="center"><%=codeToString("规格型号")%></td>
  <td width="190" align="center"><%=codeToString("生成厂家")%></td>
  <td width="190" align="center"><%=codeToString("计量单位")%></td>
        <td width="90" align="center"><%=codeToString("数量")%></td>
        <td width="90" align="center"><%=codeToString("单价")%></td>
        <td width="120" align="center"><%=codeToString("总金额")%></td>

       
 </tr>
 <%//循环输出货品浏览信息
 String S=(String)request.getParameter("id");//变量TypeID为ListMain传给View的
String AB[][];//存放Grid中的信息
AB=dgoa.GetSaleDetailPlan(S);
int K=0;//输出时的数组下标
 float TotalSum=Float.parseFloat("0") ;
 Integer i=0;
   while(K<AB.length)
   { i++; %>
  <tr bgColor="#FFFFFF" ID="GridRow<%=i %>" align="center">

  
  <td><input type="text" style="width:100%" value="<%=AB[K][2]%>" name"FullName_Name<%=i%>" id="FullName_Name<%=i%>" class="ClientTableflateditbox" readonly></td>
  
  <td><input type="text" style="width:100%" value="" name"GoodsNum<%=i%>" id="FullName_Name<%=i%>" class="ClientTableflateditbox" readonly></td>
  
  <td><input type="text" style="width:100%" name="FullName_Gg<%=i%>" id="FullName_gg<%=i%>" class="ClientTableflateditbox" value="<%=AB[K][3]%>" readonly ></td>
  
  <td><input type="text" style="width:100%" value="" name"ProduceName<%=i%>" id="FullName_Name<%=i%>" class="ClientTableflateditbox" readonly></td>
  
  <td><input type="text" style="width:100%" name="FullName_Dw<%=i%>" id="FullName_Dw<%=i%>" class="ClientTableflateditbox" value="<%=AB[K][4]%>" readonly></td>
  
  <td align="center"><input type="text" style="width:100%" value="<%=AB[K][5]%>" name="Qty_Edit<%=i%>" id="Qty_Edit<%=i%>" class="ClientTableflateditbox" readonly></td>
  
  <td align="center"><input type="text" style="width:100%" value="<%=AB[K][8]%>" name="Price_Edit<%=i%>" id="Price_Edit<%=i%>" class="ClientTableflateditbox" readonly></td>
  
  <td align="center"><input type="text" style="width:100%" value="<%=AB[K][12]%>" name="Total_Edit<%=i%>" id="Total_Edit<%=i%>" class="ClientTableflateditbox" readonly></td>
  
  
  
 </tr>

 
   <%float   f   =   Float.parseFloat(AB[K][12]); 
TotalSum=TotalSum +f ;
K++;}
String TotalSum2=Math.round(TotalSum * 100 )/100+"";
 he=heji.format(TotalSum2);

%>

 

  <tr class="ListTableHeader1" id="SumRow" height="18px">
   <td width="800" colspan="8">
   <%=codeToString(SALE_MONEY)%>
   &nbsp; <span id="GridTotal5" style="color:#000000">0</span>
   (<span id="GridTotal4" style="color:#000000">0</span><%=codeToString("元")%>)
   </td>
  </tr>
 </table>

<Script Language="javascript"> 
 GridSum();
function GridSum(){
  var QtySum;
  var PriceSum;
  var TotalSum;
  
  QtySum = 0;
  PriceSum = 0;
  TotalSum = 0;
  
  for (var i=1;i<=50;i++){
   if (document.all["Qty_Edit"+i] != null && !isNaN(document.all("Qty_Edit" + i).value) && document.all("Qty_Edit" + i).value != '' && !isNaN(document.all("Price_Edit" + i).value)){
      if ( document.all("Price_Edit" + i).value != ""){
       document.all("Total_Edit" + i).value = multiply(parseFloat(document.all("Qty_Edit" + i).value),parseFloat(document.all("Price_Edit" + i).value));
      }
      QtySum = QtySum + parseFloat(document.all["Qty_Edit"+i].value);
   }
   if (document.all["Price_Edit"+i] != null && !isNaN(document.all("Price_Edit" + i).value) && document.all("Price_Edit" + i).value != ''){
      PriceSum = PriceSum + parseFloat(document.all["Price_Edit"+i].value);
   }  
   if (document.all["Total_Edit"+i] != null && !isNaN(document.all("Total_Edit" + i).value) && document.all("Total_Edit" + i).value != ''){
      TotalSum = TotalSum + parseFloat(document.all["Total_Edit"+i].value);
   }  
  }
  //document.all.GridTotal3.innerHTML = Math.round(QtySum * 100 )/100;
  //document.all.GridTotal4.innerHTML = Math.round(PriceSum * 100 )/100;
  document.all.GridTotal5.innerHTML="<%=he%>";
  
  document.all.GridTotal4.innerHTML = Math.round(TotalSum * 100 )/100;
  
  
  
   if (document.all.Sum != null)
    document.all.Sum.value = TotalSum;
 
  
   if (document.all.Sum != null)
    document.all.Sum.value = TotalSum;
   if (document.all.PayMoney != null)
    document.all.PayMoney.value = TotalSum;
   if (document.all.ArMoney != null)
    document.all.ArMoney.value = "0";
  
 }
</Script>

 

 

 

MoneyFormat.java

 

 

class MoneyFormat{
private final String [] pattern ={"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"};
private final String [] cPattern ={"","拾","佰","仟","万","拾","佰","仟","亿"};
private final String [] cfPattern = {"","角","分"};
private final String ZEOR = "零";
public MoneyFormat(){

}

public String format(String moneyString){
int dotPoint = moneyString.indexOf("."); //判断是否为小数
String moneyStr;
if(dotPoint != -1){
moneyStr = moneyString.substring(0,moneyString.indexOf("."));
}
else{
moneyStr = moneyString;
}
StringBuffer fraction = null; //小数部分的处理,以及最后的yuan.
StringBuffer ms = new StringBuffer();
for(int i = 0;i < moneyStr.length();i++){
ms.append(pattern[moneyStr.charAt(i) - 48]); //按数组的编号加入对应大写汉字
}

int cpCursor = 1;
for(int j = moneyStr.length() - 1;j > 0;j--){
ms.insert(j,cPattern[cpCursor]); //在j之后加字符,不影响j对原字符串的相对位置
//只是moneyStr.length()不断增加
//insert(j,"string")就在j位置处插入,j=0时为第一位
cpCursor = cpCursor == 8?1:cpCursor + 1; //亿位之后重新循环
}


while(ms.indexOf("零拾") != -1){ //当十位为零时用一个"零"代替"零拾"
//replace的起始于终止位置
ms.replace(ms.indexOf("零拾"),ms.indexOf("零拾") + 2,ZEOR);
}
while(ms.indexOf("零佰") != -1){ //当百位为零时,同理
ms.replace(ms.indexOf("零佰"),ms.indexOf("零佰") + 2,ZEOR);
}
while(ms.indexOf("零仟") != -1){ //同理
ms.replace(ms.indexOf("零仟"),ms.indexOf("零仟") + 2,ZEOR);
}
while(ms.indexOf("零万") != -1){ //万需保留,中文习惯
ms.replace(ms.indexOf("零万"),ms.indexOf("零万") + 2,"万");
}
while(ms.indexOf("零亿") != -1){ //同上
ms.replace(ms.indexOf("零亿"),ms.indexOf("零亿") + 2,"亿");
}
while(ms.indexOf("零零") != -1){//有连续数位出现零,即有以下情况,此时根据习惯保留一个零即可
ms.replace(ms.indexOf("零零"),ms.indexOf("零零") + 2,ZEOR);
}
while(ms.indexOf("亿万") != -1){ //特殊情况,如:100000000,根据习惯保留高位
ms.replace(ms.indexOf("亿万"),ms.indexOf("亿万") + 2,"亿");
}
while(ms.lastIndexOf("零") == ms.length()-1){ //当结尾为零j,不必显示,经过处理也只可能出现一个零
ms.delete(ms.lastIndexOf("零"),ms.lastIndexOf("零") + 1);
}


int end;
if((dotPoint = moneyString.indexOf(".")) != -1 ){ //是小数的进入
String fs = moneyString.substring(dotPoint + 1,moneyString.length());
if(fs.indexOf("00") == -1 || fs.indexOf("00") >= 2){//若前两位小数全为零,则跳过操作
end = fs.length() > 2?2:fs.length(); //仅保留两位小数
fraction = new StringBuffer(fs.substring(0,end));
for(int j = 0;j < fraction.length();j++){
fraction.replace(j,j+1,this.pattern[fraction.charAt(j) - 48]); //替换大写汉字
}
for(int i = fraction.length();i > 0;i--){ //插入中文标识
fraction.insert(i,cfPattern[i]);
}
fraction.insert(0,"元"); //为整数部分添加标识
}
else{
fraction = new StringBuffer("元整");
}

}
else{
fraction = new StringBuffer("元整");
}

ms.append(fraction); //加入小数部分
return ms.toString();
}

}

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值