关闭

计算找零

标签: 表单
94人阅读 评论(0) 收藏 举报
<html>
<head>
<title>Insert title here</title>
</head>
<body>
	<script language="JavaScript">
	function money(){
   		facmoney = parseInt(document.form1.facmoney.value);
   		realmoney = parseInt(document.form1.realmoney.value);
   		money = facmoney - realmoney;
   		H = parseInt(money/100);
    	F = parseInt((money%100)/50);
   		E = parseInt(((money%100)%50)/20);
   		T = parseInt((((money%100)%50)%20)/10);
    	Fiv = parseInt(((((money%100)%50)%20)%10)/5);
    	Y = parseInt(((((money%100)%50)%20)%10)%5)/1;
		document.form1.M.value = money;
		document.form1.H.value = H;
		document.form1.F.value = F;
		document.form1.E.value = E;
		document.form1.T.value = T;
		document.form1.Fiv.value = Fiv;
		document.form1.Y.value = Y;
	}
    </script>
    <form name="form1">
    	实收金额:<input name="facmoney" type="text"><br>
    	应收金额:<input name="realmoney" type="text"><br>
    	<input type="button" value="计算" onclick="money()"><br><hr>
    	找零  :     <input type="text" name="M">元<br>   
    	100:<input type="text" name="H">张<br>
    	50:<input type="text" name="F">张<br>
    	20:<input type="text" name="E">张<br>
   	10:<input type="text" name="T">张<br>
    	5:<input type="text" name="Fiv">张<br>
    	1:<input type="text" name="Y">张<br>
    	</form>
</body>
</html>
<pre class="java" name="code"><%@page import="java.util.*" contentType="text/html; charset=gb2312" %>
<%!
    Map<String,Integer> MoneyMap = new HashMap<String,Integer>();
    private final int F=50;
    private final int E=20;
    private final int T=10;
    private final int Fiv=5;
    private final int Y=1;
	int money,num=0;
    
    private void CalMoney(int money) {
    		num = money/F;
    	    MoneyMap.put(F+"元",num);
    	    num = (money%F)/E;
    	    MoneyMap.put(E+"元",num);
		    num = ((money%F)%E)/T;
		    MoneyMap.put(T+"元",num);
	    	num = (((money%F)%E)%T)/Fiv;
	    	MoneyMap.put(Fiv+"元",num);
	    	num = ((((money%F)%E)%T)%Fiv)/1;
	    	MoneyMap.put(Y+"元",num);

    } 
%>
<%
	String realmoney = "";
	realmoney = request.getParameter("money");
	if(realmoney != null && !realmoney.equals(" ")){
		try{
			money = Integer.parseInt(realmoney);
			CalMoney(money);
		}catch(NumberFormatException e){
			out.print("输入错误");
		}
		}
	%>

<html>
<head>
<title>Money Number</title>
</head>
<body>
			<%@ include file="test_Log.jsp" %>
	 	<form name="form" action="test_test.jsp" method="post">
		输入金额:<input type="text" name="money"><input type="submit" value="提交"><br>
			<%
				Set set = MoneyMap.keySet();
				Iterator it = set.iterator();
				for(; it.hasNext(); ){
					String key = (String)it.next();
					Integer value = MoneyMap.get(key);
					out.print(key+" :");
					out.print(value+"<br>");
				
		 	}
				%>
			<%@ include file="test_Moneybottom.jsp" %>
	 	</form>
</body>
</html>



   
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:372次
    • 积分:31
    • 等级:
    • 排名:千里之外
    • 原创:3篇
    • 转载:0篇
    • 译文:0篇
    • 评论:0条
    文章分类
    文章存档