PDA

View Full Version : Addition of Two textboxs Im Getting Infinite value.


rajaramesh
03-05-2009, 10:28 AM
Hi friends,

I designed page1 and page2 in jsp.
page1 is input page, page2 just like report page input values and with total for inputs.
My limit is 8 digits before decimal 2 digits after decimal.
When I am entering values(8 digit number) like 99999999.25 in textbox1 and 99999999.56 in textbox 2. When it goes to page2 i.e report page. the values are like 2.36523E52, 25364E25.
At the same time the result is also the same like infinite value.

Here is the code:

[CODE]

page1:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<title>Page1</title>

<head>
<center><h1>Page1</h1></center>
<%@ page language="java" %>

</head>
<html>
<form action="page2.jsp" method="post">

<table width="97%" align="center" cellspacing="2" cellpadding="2">

<tr><td width="40%">STP Unit</td>
<td width="75%" align="left"><input type="text" name="STPU" size="40"></td></tr>

<tr><td width="40%">CEO</td>
<td width="15%" align="left"><input type="text" name="CEO" size="40">


</tr>
<td align="center">
<input type="submit" value="Next Page" >&nbsp&nbsp<input type="button" value="Cancel" onclick="forward()"></td>
</table>
</form>
</html>



Page2:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<title>Page2</title>

<head>
<center><h1>Page2</h1></center>
<center><b>Report.</b></center>
</head>

<%
String uname=request.getParameter("STPU");
session.setAttribute("aa",uname);
String username=(String) session.getAttribute("aa");

double usernameA=Double.parseDouble(username);

String un=request.getParameter("CEO");
session.setAttribute("bb",un);
String usernam=(String) session.getAttribute("bb");

double username1=Double.parseDouble(usernam);

double Total=usernameA+username1;
%>

<html>
<table width="97%" align="center" cellspacing="2" cellpadding="2">

<tr><td width="40%">STP Unit</td>
<!--<td width="75%" align="left"><input type="text" name="STPU" size="40" value="<%= request.getParameter("STPU") %> "></td></tr>-->
<td width="75%" align="left"><input type="text" name="STPU" size="40" value="<%=usernameA%>"></td></tr>

<tr><td width="40%">CEO</td>
<!--<td width="15%" align="left"><input type="text" name="CEO" size="40" value="<%=session.getAttribute("CompCEO") %>">-->
<td width="15%" align="left"><input type="text" name="CEO" size="40" value="<%=username1%>">

<tr><td width="40%">CEO1</td>
<td width="15%" align="left"><input type="text" name="CEO1" size="40" value="<%=Total%>">

<td align="center">
<input type="button" value="Proceed to Save">&nbsp&nbsp<input type="button" value="Cancel"></td>

</table>
</html>


[CODE]

Please Helpme.

Thanks in Advance..

regards
rajaramesh.

milindpatil
03-05-2009, 01:54 PM
Your code is working properly for me. I did not change anything in it.
For same values of STPU and CEO as mentioned I am getting this displayed on the page2.jsp

STP Unit - 9.999999925E7
CEO - 9.999999956E7
CEO1 - 1.9999999881E8


Perfect calulations.

Also why are you doing setAttribute and getAttribute from session? :confused: Totally not needed here. Of course if you are planning somthing else ahead or just practicing. :thumbsup:

rajaramesh
03-05-2009, 02:45 PM
Your code is working properly for me. I did not change anything in it.
For same values of STPU and CEO as mentioned I am getting this displayed on the page2.jsp

STP Unit - 9.999999925E7
CEO - 9.999999956E7
CEO1 - 1.9999999881E8


Perfect calulations.

Also why are you doing setAttribute and getAttribute from session? :confused: Totally not needed here. Of course if you are planning somthing else ahead or just practicing. :thumbsup:

Thanks for your Reply patil.

It is working properly upto 7 digit number with decimal or without decimal.
But when i go for 8 digit number with decimal it is showing me the output in page2 like above you shown to me. But really a 8 digit numbers sum is not a infinite number.like (STP Unit - 9.999999925E7
CEO - 9.999999956E7
CEO1 - 1.9999999881E8) see you got 25E7 at STPUnit,56E7 for CEO, 81E8 for CEO1 i.e for total for both STP and CEO.

milindpatil
03-06-2009, 12:37 PM
But really a 8 digit numbers sum is not a infinite number.like (STP Unit - 9.999999925E7
CEO - 9.999999956E7
CEO1 - 1.9999999881E8) see you got 25E7 at STPUnit,56E7 for CEO, 81E8 for CEO1 i.e for total for both STP and CEO.


Not sure if I got you right.. but I figure that you are taking 9.999999925E7, 1.9999999881E8 as infinite numbers. Which is wrong.

9.999999925E7 = 9.999999925 * 10^7 = 99999999.25

rajaramesh
03-07-2009, 01:15 PM
How do i Convert this number to actual number 9999999.25.
Please help me in this ... i am working on this since 7 days of time..
Please plz...

regards
rajaramesh




But really a 8 digit numbers sum is not a infinite number.like (STP Unit - 9.999999925E7
CEO - 9.999999956E7
CEO1 - 1.9999999881E8) see you got 25E7 at STPUnit,56E7 for CEO, 81E8 for CEO1 i.e for total for both STP and CEO.


Not sure if I got you right.. but I figure that you are taking 9.999999925E7, 1.9999999881E8 as infinite numbers. Which is wrong.

9.999999925E7 = 9.999999925 * 10^7 = 99999999.25