User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JSP section within the Web Development category of DaniWeb, a massive community of 392,043 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,267 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JSP advertiser: Lunarpages JSP Web Hosting
Views: 468 | Replies: 4 | Solved
Reply
Join Date: Jan 2008
Posts: 27
Reputation: eddy556 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
eddy556 eddy556 is offline Offline
Light Poster

Mathematical operators

  #1  
Feb 5th, 2008
I'm having problems performing math in JSP. I have a line:

double percentage = (useful / nonuseful) * 100;

which is giving me an error, how do I fix this?

Thanks
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jan 2008
Posts: 32
Reputation: electron33 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 4
electron33 electron33 is offline Offline
Light Poster

Re: Mathematical operators

  #2  
Feb 5th, 2008
<%
double useful = 12;
double nonuseful = 24;
double percentage = ( useful / nonuseful ) * 100;
%>
<%= percentage %>


In this example it will be 50.0 in the JSP page.
Last edited by electron33 : Feb 5th, 2008 at 3:17 pm.
Reply With Quote  
Join Date: Jan 2008
Posts: 27
Reputation: eddy556 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
eddy556 eddy556 is offline Offline
Light Poster

Re: Mathematical operators

  #3  
Feb 5th, 2008
Okay now I'm getting errors about doubles and integers the values in the database are stored as doubles

Type mismatch: cannot convert from double to int

136: double useful = columns.getDouble("Customer_Useful");
137: double nonuseful = columns.getDouble("Customer_NotUseful");
138: votes = useful + nonuseful;
139: double percentage = (useful / nonuseful) * 100;
Reply With Quote  
Join Date: Jan 2008
Posts: 32
Reputation: electron33 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 4
electron33 electron33 is offline Offline
Light Poster

Re: Mathematical operators

  #4  
Feb 6th, 2008
Can you paste me the whole code. Including variable declaration. Some where in the declaration a variable have been declared int.
Reply With Quote  
Join Date: Jan 2008
Posts: 27
Reputation: eddy556 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
eddy556 eddy556 is offline Offline
Light Poster

Re: Mathematical operators

  #5  
Feb 6th, 2008
Its ok its been solved now
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb JSP Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the JSP Forum

All times are GMT -4. The time now is 11:16 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC